答:
I think this really depends on your target audience, and the license model under which your application is developed (i.e open source or closed source). I know your question mentions who your target audience is in this particular case, but in order to provide an answer that is useful to everyone I think this is best ignored for answers.

As a developer you want to be getting as much feedback as possible for issues and bugs, and the easier you make it for users, the more likely they are to do so.

Providing an email address, or as mentioned by Florian Margaine, a contact form, is probably the best option. This will result in far more feedback from users, and will make it far more likely that bugs are reported. As you can imagine though, you will receive multiple reports for each bug - this is both a positive and a negative. On the one hand it will result in a lot of duplication of issues, but this can be a positive in that it lets you see just how many users are encountering the issue, and you can the prioritise it accordingly.

Providing a link to github or any other bug tracking system may confuse the average user, so if your product is going to be used by inexperienced users, then this may be best avoided. If you must direct them to such a system, then make sure they can submit a bug report by entering as few details as possible - just a title and description is all you really need, anything else can be added later.

If your product is going to be open source, however, then there is an added bonus that by linking to github or similar, not only can users report bugs, but see what bugs are being reported and fix them themselves.

So for an open source product or a product that targets a highly technical user base, then linking to github may be the best bet, but for your average user, an email address or contact form may suffice.

However, there is no reason that you cannot do both, thereby letting the user choose which system they find is most suitable to their abilities.


问:
Where can I find a legal "permission to work on open source" document?
One of the things I really like about my current job is that we developers are encouraged to make open source contributions.

However, this encouragement has always been verbal. I've read some horror stories about developers having their open-source work legally claimed by their employer. I'd be more comfortable if we had something in writing from my employer saying that contributions are allowed and not owned by the company.

Understanding that you are not lawyers, does anyone know where to find a boilerplate document to this effect?

答: Wouldn't an email or simple written permission suffice? I am about to start working on a project which my employer has verbally agreed is okay to open source. It is related to the work I'm doing with the company so I plan to get it in writing too. However, I do have a similar concern that there's no standard template that covers Permission and Ownership. As in, I have permission to do it and ownership of my work would not belong to the company exclusively (not an OSS company). If I present the Harmony Agreements mentioned above I'm sure it would just change their mind to "No". Also, it's not my company contributing to open source project, just me.

ContentLicense: CC BY-SA 3.0


问:
Where to put code documentation?
I am currently using two systems to write code documentation (am using C++):

Documentation about methods and class members are added next to the code, using the Doxygen format.  On a server Doxygen is run on the sources so the output can be seen in a web browser

Overview pages (describing a set of classes, the structure of the application, example code, ...) is added to a Wiki

I personally think that this approach is easy because the documentation about members and classes is really close to the code, while the overview pages are really easy to edit in the Wiki (and it's also easy to add images, tables, ...).  A web browser allows you to see both documentations.

My co-worker now suggests to put everything in Doxygen, because we can then create one big help file with everything in it (using either Microsoft's HTML WorkShop or Qt Assistant).  My concern is that editing Doxygen-style documentation is much harder (compared to Wiki), especially when you want to add tables, images, ... (or is there a 'preview' tool for Doxygen that doesn't require you to generate the code before you can see the result?)

What do big open-source (or closed source) projects use to write their code documentation?  Do they also split this up between Doxygen-style and a Wiki?  Or do they use another system?

What is the most appropriate way to expose the documentation?  Via a Web server/browser, or via a big (several 100MB) help file?

Which approach do you take when writing code documentation?

答:
Having all documentation in one system instead of two can be a real advantage. Things like backup & restore, versioning, global search, global search&replace, cross-linking, and, as you wrote, putting all docs in one final document, will typically work with less "friction" when you don't have to maintain two different systems with overlapping capabilites.

On the other hand, you have to think about if these advantages outweigh the easiness of your Wiki. The edit/generate/refine edit/generate again circle may be quicker with your Wiki. I guess that you can get that cycle quite fast with doxygen keeping your overview pages as a separate doxygen subproject. You can make use of the external linking capabilities of doxygen, which is not a replacement for a "quick preview", of course, but a step towards that direction. I have not done this by myself, so far, but I guess you must try that out for yourself if you want to know if it works in your case.

Concerning other projects: I think a tool like doxygen is primarily for library documentation. If you are not a third-party library vendor, and everyone using your libraries has full access to the source code, then the need for a tool like doxygen is questionable. In our team, for example, we have almost no external docs outside of the code except end user docs and the docs of our database models. Our primary tools for that kind of documentation are  docbook and fop, which gives us satisfying results.

Title: Where to put code documentation?

ContentLicense: CC BY-SA 4.0


问:
Database GUI Programming - .Net vs MS Access
MS Access gets pooped on a lot because A) many newbies use it B) people use it as a database backend which is not a good idea.

I'd like to see some reasonable discussion on why you might choose VB.Net over MS Access or vice versa for programming a Database GUI (forms and reports) to be used with MS SQL Server.

答:
I was hired a while ago in a company which uses Access xp with a SQL server database backend, and I've got to tell you, the argument of scalability is inmediately seen with this application.

While you can setup a form or report really quickly with access, it gives you no control over threading, chokes up with too much data to process, and its kind of lacking in the controls department.

So unless it's only a couple of inexperienced computer users that are going to use the app, I'd suggest you avoid access at all cost.

ContentLicense: CC BY-SA 2.5


问:
What's the difference between Entry Level/Jr/Sr developers?
Other than title and pay, what is the difference?

What different responsibilities do they have.

How knowledgeable/experienced are they?

What is the basic measure to determine where a developer fits into this basic structure?

答:
Simply put and from personal observations found on job posting sites and only regarding experience levels.

Entry = Your new probably your first job.

Junior = Your good but not supposed to be the best, you also usually have less then 5 years and more than 2 years experience.

Senior = You are supposed to be the best and do have more than 5 years experience.


问:
.NET app - Should we use SQL Server and duplicate some reference data from an external Oracle DB? Or use Oracle and have a DB link?
We're looking to migrate some existing Excel/Access processes into a new system which will provide the users with a Silverlight frontend to run and view the reports instead of using MS Access. The initial idea was to have SQL Server 2008 as RDBMS.

The problem is that we've got some static data such as country codes, counterparties, etc which live in an existing Oracle DB.
Since we do not want to duplicate that data (if possible), we were thinking of having a DB link between SQL Server and Oracle, but our firm does not allow that.

So the options are either duplicate the data or use Oracle as RDBMS - surprise, the firm does allow DB links between Oracle databases.

The initial idea was also to use WCF RIA Services, Entity Framework, etc which we're not sure they play well with Oracle, that's why it was decided to go with SQL Server in the first place.

Would you advise to go for Oracle so that we can just link the static data? Or use SQL Server 2008 and replicate it because it's "safer" to stay within the Microsoft land? To use or not to use Entity Framework and WCF RIA Services at all?

Regards.

UPDATE: Thanks everyone for your answers. Nothing is set in stone yet. We'll try to import the data instead of linking, as if the other DB goes down, our system can still carry on. We're likely to use SQL Server just because most developers are more experienced with it. Even if we used RIA Services, we can swap out the Data Access Layer and use other frameworks such those mentioned below.

答:
The key question to ask here to make a reasonable decision is

who maintains that static data, how (and how often) are updates/changes/bugfixes are provided?

If the answer is "The software developers of the System", then maintain those data outside of any database and provide some SQL scripts for initializing or updating the data. This can be done in a way you have to maintain the data in one place, either by using DB independent SQL scripts or by building a SQL generator for each system.

If the answer is "Some users connected to the Oracle system, and the data must not be instantanously available at the MS SQL DB", then better provide some extract-transform-load process (to be run in reasonable intervals) to get the data out of the Oracle DB into your MS SQL DB. Advantage: if the Oracle DB is going offline, your system still works, you have a much higher availability and the whole developing and testing will be easier since you decouple yourself from a third system.

Only if the answer is "the data must be instantanously available", think about using the same database (system) for the static data and your system.

I would normally not make a decision between MS SQL DB and Oracle because of "some static data". Both systems are mature and provide a rich development infrastructure. Ask your company/customer what database they prefer, this is mainly a question of which database know-how is already there, do they want to live with a mixed DB infrastructure or not etc. If the company is using primarily Oracle, then use Oracle. If they have both kinds of DB, ask what they prefer for the future.


答:
The DailyWTF is littered with companies that put in new systems for the sake of it rather than go with what works, learn from them :)

EF does (mostly) work with Oracle, but frankly, I'd avoid EF in the first place and go with a different ORM. My experiences with EF were not the best when we did a very large system using it. Fortunately, there are alternatives that are better - DevArt did some work to make an ORM that works with Oracle's features and it superior to EF, Castleprojects' ActiveRecord might be suitable for you, or SubSonic has a very good ORM, you could even use NHibernate.

So, I'd go with the existing Oracle infrastructure, it'll fit better with your company and that is always a big win, if only for the DBAs who can apply all their backup and maintenance expertise to your data.

Title: .NET app - Should we use SQL Server and duplicate some reference data from an external Oracle DB? Or use Oracle and have a DB link?

Body:
We're looking to migrate some existing Excel/Access processes into a new system which will provide the users with a Silverlight frontend to run and view the reports instead of using MS Access. The initial idea was to have SQL Server 2008 as RDBMS.

The problem is that we've got some static data such as country codes, counterparties, etc which live in an existing Oracle DB.
Since we do not want to duplicate that data (if possible), we were thinking of having a DB link between SQL Server and Oracle, but our firm does not allow that.

So the options are either duplicate the data or use Oracle as RDBMS - surprise, the firm does allow DB links between Oracle databases.

The initial idea was also to use WCF RIA Services, Entity Framework, etc which we're not sure they play well with Oracle, that's why it was decided to go with SQL Server in the first place.

Would you advise to go for Oracle so that we can just link the static data? Or use SQL Server 2008 and replicate it because it's "safer" to stay within the Microsoft land? To use or not to use Entity Framework and WCF RIA Services at all?

Regards.

UPDATE: Thanks everyone for your answers. Nothing is set in stone yet. We'll try to import the data instead of linking, as if the other DB goes down, our system can still carry on. We're likely to use SQL Server just because most developers are more experienced with it. Even if we used RIA Services, we can swap out the Data Access Layer and use other frameworks such those mentioned below.


问:
Anonymous function vs. separate named function for initialization in jquery
Let's say we have some code that is used to initialize things when a page is loaded and it looks like this:

```<code>function initStuff() { ...}
...
$(document).ready(initStuff);
</code>```

The initStuff function is only called from the third line of the snippet. Never again. So usually people put this into an anonymous callback like this:

```<code>$(document).ready(function() {
    //Body of initStuff
});
</code>```

Having the function in a dedicated location in the code is not really helping with readability, because with the call on ready() makes it obvious that this is initialization code.

Are there any other reasons to prefer one over the other?

答:
I'd say in this case it probably doesn't matter, but if you have anonymous callback functions, calling other anonymous callback functions, I tend to use the first approach, as it makes the code a lot more readable and easier to follow.

With regards to unit testing, the first approach would be better, as you would be able to test the initstuff function in isolation.


答:
Some use other systems - take a look at Python's Sphinx for example, they have a all-in-one doc system that build everything (it also works for C/C++)

I always think of documentation as being separate to the code, doxygen is great, but it is for an overview of the API, not 'documentation'. For that, a wiki is great, but I prefer to use ASCIIDOC and store the results of that in source control along with the code, mainly because I can generate PDFs from it to hand to other people (eg the testers, customer, etc)

Title: Where to put code documentation?

Body:
I am currently using two systems to write code documentation (am using C++):

Documentation about methods and class members are added next to the code, using the Doxygen format.  On a server Doxygen is run on the sources so the output can be seen in a web browser

Overview pages (describing a set of classes, the structure of the application, example code, ...) is added to a Wiki

I personally think that this approach is easy because the documentation about members and classes is really close to the code, while the overview pages are really easy to edit in the Wiki (and it's also easy to add images, tables, ...).  A web browser allows you to see both documentations.

My co-worker now suggests to put everything in Doxygen, because we can then create one big help file with everything in it (using either Microsoft's HTML WorkShop or Qt Assistant).  My concern is that editing Doxygen-style documentation is much harder (compared to Wiki), especially when you want to add tables, images, ... (or is there a 'preview' tool for Doxygen that doesn't require you to generate the code before you can see the result?)

What do big open-source (or closed source) projects use to write their code documentation?  Do they also split this up between Doxygen-style and a Wiki?  Or do they use another system?

What is the most appropriate way to expose the documentation?  Via a Web server/browser, or via a big (several 100MB) help file?

Which approach do you take when writing code documentation?


答: I don't know about "WCF RIA Services, Entity Framework" working with Oracle or not, but your company seems to rely heavily on Oracle; I would stick with it. In an enterprise situation, everyone needs to plan things out and get on the same page. Having multiple copies of data IMHO is a bad idea without some sort of link or replication. Obviously someone needs to think twice about altering any of these tables without considering your app as well.</p>


问:
How to manage a developer who has poor communication skills
I manage a small team of developers on an application which is in the mid-point of its lifecycle, within a big firm. This unfortunately means there is commonly a 30/70 split of Programming tasks to "other technical work". This work includes:

Working with DBA / Unix / Network / Loadbalancer teams on various tasks

Placing and managing orders for hardware or infrastructure in different regions

Running tests that have not yet been migrated to CI

Analysis

Support / Investigation

Its fair to say that the Developers would all prefer to be coding, rather than doing these more mundane tasks, so I try to hand out the fun programming jobs evenly amongst the team.

Most of the team was hired because, though they may not have the elite programming skills to write their own compiler / game engine / high-frequency trading system etc., they are good communicators who "can get stuff done", work with other teams, and somewhat navigate the complex bureaucracy here. They are good developers, but they are also good all-round technical staff.

However, one member of the team probably has above-average coding skills, but below-average communication skills. Traditionally, the previous Development Manager tended to give him the Programming tasks and not the more mundane tasks listed above. However, I don't feel that this is fair to the rest of the team, who have shown an aptitude for developing a well-rounded skillset that is commonly required in a big-business IT department.

What should I do in this situation? If I continue to give him more programming work, I know that it will be done faster (and conversely, I would expect him to complete the other work slower). But it goes against my principles, and promotes the idea that you can carve out a "comfortable niche" for yourself simply by being bad at the tasks you don't like.

I want to clarify that I'm not trying to address this issue due to a grudge, or that I have a "chip on my shoulder" as was mentioned. I'm looking for advice on how to keep a well-rounded team, which is happy and motivated. By observing the variety of answers to this question, it seems like there are a lot of different opinions on how to achieve this.

答:
People are different. As a manager, you need to treat people differently (but fairly!) to get the most out of your team.

That said, it's probably good for the developer with poor soft skills to work on them. I would figure out what non-coding thing the developer enjoys (or would like to do) that involves more of those soft skills. Get them engaged on that task, and ideally they'll improve the soft skills as a side effect.

People often aren't bad at something to get out of work; they're bad at it because they don't enjoy it or have an aptitude for it. You can't help the latter, so work on the former.


问:
How do you keep released binaries under version control?
How do you keep released binaries under version control?
This allows to track which stuffs are changed between each release.
I mean to separate the released binaries from source repository.
The released binaries are either built from Continuous Integration software or manually compiled.</p>

答:
Just put them in. There's no problem with that, unless you're using git (which doesn't merge binaries well, so you'll have to manage them yourself) or you're committing them too many times (only commit when it's ready to ship, not everytime you build it).

Most SCMs delta binaries quite well, we used to put a 2Mb resource dll into our SVN and it would delta to a few kb each time.

I hear a lot of arguments that SCMs are for source, not binaries but this is plainly false when you consider most software consists of images, even if they are just icon files. They're binaries, but they are part of the source, so put them in and don't be so dogmatic about it.
I also hear that you can just rebuild the binary when needed, often this is the case, but it can be a huge time-wasting effort for older systems that are no longer actively supported. If you have to re-create a system with only older service packs or patches to correspond with the system that was used to build a binary 3 years ago, you'll be glad you added the bin to your SCM back then.

The only time you need to worry about adding builds to your SCM is if you're doing it automatically as part of the build server process  - don't do this. You will fill your SCM up with builds that have no benefit to you. Instead only add them when they are released. This way you know exactly what your customer has and you can reproduce any customer-reported issues with the binaries they are using, and not ones that you've rebuilt (using, lets say, latest updates to the compiler or the OS).


答:
Although you are trying to manage a team and want to keep everyone motivated (having a sense of fairness helps), but are you sacrificing the project by not having your best programmer programming? I mean, this is the point isn't it.

Aren't you afraid of underutilizing and/or risk losing your best developer? Your job is to try and relieve these types of duties from everyone.

Being treated equally doesn't mean you treat everyone the same. If the others want to slack off the non-programming duties in order to be assigned more programming tasks, aren't they running the risk of being good at neither?

EDIT:  Other than your personal feelings, you haven't identified a problem. At some point the lack of communication hinders a programmer. Others will show resentment and their work may suffer. So far, you seem to be the only one having a problem. Unless there is something else you're not sharing?

EDIT 2
Eventually, everyone is going to ask for a special favor. This person does less communicating and more coding (which he should by all accounts). Someone else wants to come in a little later. Another will need to skip a meeting to fulfill a deadline. A graphics person gets a bigger monitor. When you put too much emphasis on keeping score, you forget what is important.

Title: How to manage a developer who has poor communication skills

Body:
I manage a small team of developers on an application which is in the mid-point of its lifecycle, within a big firm. This unfortunately means there is commonly a 30/70 split of Programming tasks to "other technical work". This work includes:

Working with DBA / Unix / Network / Loadbalancer teams on various tasks

Placing and managing orders for hardware or infrastructure in different regions

Running tests that have not yet been migrated to CI

Analysis

Support / Investigation

Its fair to say that the Developers would all prefer to be coding, rather than doing these more mundane tasks, so I try to hand out the fun programming jobs evenly amongst the team.

Most of the team was hired because, though they may not have the elite programming skills to write their own compiler / game engine / high-frequency trading system etc., they are good communicators who "can get stuff done", work with other teams, and somewhat navigate the complex bureaucracy here. They are good developers, but they are also good all-round technical staff.

However, one member of the team probably has above-average coding skills, but below-average communication skills. Traditionally, the previous Development Manager tended to give him the Programming tasks and not the more mundane tasks listed above. However, I don't feel that this is fair to the rest of the team, who have shown an aptitude for developing a well-rounded skillset that is commonly required in a big-business IT department.

What should I do in this situation? If I continue to give him more programming work, I know that it will be done faster (and conversely, I would expect him to complete the other work slower). But it goes against my principles, and promotes the idea that you can carve out a "comfortable niche" for yourself simply by being bad at the tasks you don't like.

I want to clarify that I'm not trying to address this issue due to a grudge, or that I have a "chip on my shoulder" as was mentioned. I'm looking for advice on how to keep a well-rounded team, which is happy and motivated. By observing the variety of answers to this question, it seems like there are a lot of different opinions on how to achieve this.


答:
It sounds like you are placing too much effort on having well rounded individuals and not enough effort on having a well rounded team.

There is nothing wrong with being good at something--in fact, that is probably why he was hired! You should be thankful to have someone who is good at programming to begin with.

You stated:

... it goes against my principles, and promotes the idea that you can
  carve out a "comfortable niche" for yourself simply by being bad at
  the tasks you don't like.

If he was a mediocre programmer, then I'd agree. But you didn't say that. You said he was a good programmer. He's not being bad at the other tasks to get out of them--he's merely focused his efforts on becoming a better programmer. There is nothing wrong with that.

As a manager, it is not your job to make sure that everyone is "well rounded". It is your job to make sure that s*** gets done. And you're not doing that. In fact, you're making decisions that are stopping things from getting done.

Whatever problem you have, you need to get over it--you are making your team less productive.


答:
I have 2 things to say on this

Have you recruited a coder or a software developer?

When you are considering a software developer all the things you have mentioned are part and parcel of software development.You just cannot ignore any these unless you have recruited for just a specific task. IMO 50% of total software development is coding rest all is design,analysis,testing,documentation,etc.

No one is born perfect.

It just cant be that you can find a person who is good in everything. You have to make them struggle and make them learn things.

As manager you have to get the best out of them I agree but in long term running you might face problems.Assign them light tasks so that they tend to get a grip of it. Get out them the feeling that I am not good at this/ I cannot afford to do this. Most of all treat everyone equally that will get the most efficient output from your team.


答:
You are catching some heat here in the other answers for your decision to "do something" about this guy, but I fully get what you are saying. If the other team members "would all prefer to be coding, rather than doing these more mundane tasks" then they are going to be annoyed that you are rewarding the bad performance of the poor communicator by giving him just the tasks that everyone wants.

Imagine you are one of the "good communicators" on the team who's skills are comparable to the dev in question. You handle calls, work with other non-IT staff who barely know a mouse from a keyboard, write up plans for user sign-off, and more, all because your boss says to do it. The grumpy dev, in the meantime, because he has "poor communication skills", gets to sit back in his cube all day ignoring the users working on the "fun" stuff only.

Now you said that the grumpy dev has "above average" skills, but you didn't say he was the best. This means that maybe 1/3rd of your team, those good communicator devs who are the grumpy dev's skill level or above, are all feeling pissed off.

Is it worth loosing some productivity from your BEST PERFORMING STAFF because they are annoyed with the grumpy-dev? You'll have to decide.

Unless you want to fire the guy, I suggest you take one of these approaches:

1) Mentor him to be a better communicator. Only you can tell if this is feasible. You might find just holding his hand a little more might help. Some people are just terrified of formal business interactions and express it by being pissed off when asked to do it.

2) Incentivize the "good communication", either with money or other benefits. Make it clear that you actually value good communicators and then your devs won't be so annoyed, but the reward has to be real & meaningful. "Lunch with the district manager" won't cut it. Neither will an "star player/kudos/attaboy" award that's just a piece of paper. Its gotta be extra money, extra leave, some flex time, some serious recognition with higher-ups who control pay raises, etc.


答:
Does your software going to be read-only of that external database ?
Does your software going update, insert, delete, that external database ?

If your answers are "yes", and "no":

(1) You mention "external [SQL] database". Wheter is Oracle, Ms.SQL Server, or other.

Several proyects, I have worked on, had several technical problems, among different "sql vendors".

I suggest to make a copy of that external Oracle Database to an internal [Put your local SQL Brand] Database. Using a schema, if not equal, as similar as possible, to the original one. Make a process to import the data.

Advantages

This way, you leave the source data untouched, problems of access, compatibility, security issues.

Disadvantages

Adding an extra layer of data and logic. Extra work.

(2) For the library framework, such as M.S. "Entity",WPF, whatever, you may want to check, your company's policy, and Technology Development choices at long term.

I understand this point seems not related, to the question, but, in real world, this affects, specially with M$ software.

I already met a few cases, where companies migrated from other database to Oracle, due to its stability (Im not related to Oracle or M$).

You mention "Silverlight", which has been officially deprecated, by M$.

Cheers.


答:
If everyone on your staff has the same title/job description and the job description includes everything you listed then this programmer needs to have these other skills sharpened by getting assigned more of these other non-programmer tasks. Likewise your other staff will not have their programming skills sharpened if they continually have to work on non-programming tasks (use it or lose it).

But I still think that your main priority should probably be meeting your deadlines (which you might still be able to do while distributing the work evenly).

EDIT:
If you have a small team it probably makes sense to have all the members be able to wear multiple hats. If you have a team that is large enough, it probably makes sense to have groups that specialize in different areas. From your post it looks like you don't have a large enough team to have groups of specialists.


答:
Use Code Documentation, first. Add Wiki & other methods, if possible

I know that is going to be difficult to maintain it.

Practical answer:

In practical terms, the first thing that developers do, its check the code.

As a developer, I like to have external documentation like Wiki (s) and manuals. But the first thing I do is to review the code (sometimes from other developers, sometimes, my own).

As a developer that worked in several projects and different customers, I try add external documentation when possible, but its common to have a lot of workload and not been able to support a wiki.

Sometimes project managers & other bosses doesn't care about documentation, sometimes others developers don't.

And the best I can do is to add some comments to code.

Good Luck

Title: Where to put code documentation?


答:
First of all, putting blame on your team members... denotes poor managerial skills.

I mean, if he really has poor communication skills,  I'm very sorry for his social life, but really, at work this isn't as much his problem as it is yours. And let's face it, he could actually just be bored by your dull working setting, or having private problems influencing his performance, or being secretly plotting to kill you all.

Communication takes at least two, and after all, the one with poor people skills could be you. Nevermind the rest of the team members getting along pretty well, they could all be compensating (even unknowingly) for some communication deficiency you have and blissfully ignore.

And anyway, don't go around asking the internet about people that's sitting three desks from you, go to the chap and ask him if there really is anything wrong and if it can be worked out. (or something dull that can be optimized or improved)

Maybe he just hates his desk position (is he facing the lavatories?) and this sets him in a bad mood.

Hint: listen to the answer, like he's a sentient human being, not a human resource.

(e.g.: try explaining him in detail the need of certain practices and the meaning of certain decisions, some people dig details, as they give them a sense of having a captain that isn't driving the ship into the cliffs)


答:
As @Stargazer712 mentioned, the first clutters the global namespace, so the second one is the winner IMHO. Now, having said that, because you're using an anonymous function in the second example, your debugger's callstack will be useless and will get differing results depending on the debugger you use. Ususally, what I end up going with is:

```<code>$(document).ready(function MODULE_init() {
    //Body of initStuff
});
</code>```

That way, the global namespace doesn't get cluttered and you have a useful callstack.

I tend to use the above convention in all anonymous (well, not anonymous anymore ;)) function definitions. It's a convention that I found when browsing through Firefox JS code.

Edit:
Now having said all that, Oliver brings up a good point with unit tests. The above is meant to act as a wrapper for more complex operations, not to house a ton of untested code.

Title: Anonymous function vs. separate named function for initialization in jquery

Body:
Let's say we have some code that is used to initialize things when a page is loaded and it looks like this:

```<code>function initStuff() { ...}
...
$(document).ready(initStuff);
</code>```

The initStuff function is only called from the third line of the snippet. Never again. So usually people put this into an anonymous callback like this:

```<code>$(document).ready(function() {
    //Body of initStuff
});
</code>```

Having the function in a dedicated location in the code is not really helping with readability, because with the call on ready() makes it obvious that this is initialization code.

Are there any other reasons to prefer one over the other?

Body:
As @Stargazer712 mentioned, the first clutters the global namespace, so the second one is the winner IMHO. Now, having said that, because you're using an anonymous function in the second example, your debugger's callstack will be useless and will get differing results depending on the debugger you use. Ususally, what I end up going with is:

$(document).ready(function MODULE_init() {
    //Body of initStuff
});

That way, the global namespace doesn't get cluttered and you have a useful callstack.

I tend to use the above convention in all anonymous (well, not anonymous anymore ;)) function definitions. It's a convention that I found when browsing through Firefox JS code.

Edit:
Now having said all that, Oliver brings up a good point with unit tests. The above is meant to act as a wrapper for more complex operations, not to house a ton of untested code.


答:
There is also I third way of registering init methods without cluttering the global namespace which i prefer:

```<code>jQuery(function(){....});
</code>```

It´s short and avoids DOM document lookup like

```<code>jQuery(document).ready(function(){...});
</code>```

does.

Body:
There is also I third way of registering init methods without cluttering the global namespace which i prefer:

jQuery(function(){....});

It´s short and avoids DOM document lookup like

jQuery(document).ready(function(){...});

does.


问:
Converting ANTLR AST to Java bytecode using ASM
I am currently trying to write my own compiler, targeting the JVM.

I have completed the parsing step using Java classes generated by ANTLR, and have an AST of the source code to work from (An ANTLR "CommonTree", specifically). I am using ASM to simplify the generating of the bytecode.

Could anyone give a broad overview of how to convert this AST to bytecode?

My current strategy is to explore down the tree, generating different code depending on the current node (using "Tree.getType()").

The problem is that I can only recognise tokens from my lexer this way, rather than more complex patterns from the parser.

Is there something I am missing, or am I simply approaching this wrong?

答: I am doing something along the same lines. I recommend Pragmatic's ANTLR The Definitive Guide and also Pragmatic's Language Implementation Patterns both available at their website  (with which I have zero connection)  .. I would say that both these books taken together are better than the Dragon</p>


问:
Reporting in Visual Studio 2010 Express
I want to download Visual Studio 2010 Express Edition to learn all that is new in it. I find it insufficient as there is no Crystal Reports integration in it. Apart from that I want to learn other enterprise features that are bundled with the Professional Edition.

If I download the VS 2010 Professional Edition, it is just limited to 90 days. Is there any other alternative for learners?

Also, is there any FREE alternative for reporting in Express Edition.

答: You can download and use any full version of VS2010 and try it out for 90 days (after 30 days, register it to extend it 60 more days). All of these versions (Professional, Premium, Ultimate) have Crystal Reports.

Title: Reporting in Visual Studio 2010 Express


答:
Since by your own evaluation this one programmer is the best on the team, in a way it is "fair" to give that person the desired job (as a result of having demonstrated being best able to do it).  After all, there were probably people who would have liked to work at this company but weren't hired at all - but nobody's going to say it isn't "fair" to them that they don't get to do this coding.

I think a fair approach would be to tell another, less skilled member of the team who wants to do more coding: "we're letting (so-and-so) take the lead on this one.  Perhaps you can take the lead on the next thing that comes along, if you can demonstrate having learned x and y skills."


问:
Is gettext appropriate for internationalizing user help documentation?
On my project, we have po files to internationalize/translate various labels, error messages, button-text etc. We also have separate po files for the entirety of our help documentation, which is included in the product.

Is this an appropriate use of gettext - putting entire documents in po files as opposed to just labels and messages?

The format has been made all the more complicated because sometimes (for tooltips or "what's this" icons) only a small part of the help doc is needed, resulting in single phrases/paragraphs being entries in the po file, which are then concatenated together when the user views the help... making the actual act of translation challenging.

Is there a better way to internationalize end user help documentation?

答: I would probably not consider storing entire documents in your i18n files. As you've noted, these are better suited for small chunks of text that is normally hard coded into the application. Your help documents are more-or-less entities that can be stored else-where, perhaps in a database so it's easy to update them on the fly. Then you can load the document that corresponds to the user's language settings. This way they can be maintained independently of your application and by non-developers. Another advantage of externalizing the documents is so that you can generate other forms of end-user documentation with out resorting to parsing your i18n files.</p>


答:
Like some of the others who answered, I understand your position, and I would have similar ambitions.

While the is a case to say that it makes sense to give tasks to the people best equipped to carry them out, there is also sense in broadening peoples skills in order to provide a dynamic and flexible team.

If this guy is required to do do non-coding elements in his role, but his communication skills are poorer than are really needed, he needs to improve. On the assumption that you have some kind of development review/appraisal system, this is the time to raise the issue.

The key issues are to map out clearly what you require of him, assess whether he has the skills to comply, and work out a training plan to enable to do so. Training doesn't necessarily need to be formal, but you need to help him gain the skills required.

If he simply can't be bothered, then it would ultimately come to a disciplinary issue. If he doesn't have the ability, despite having tried and having been supported by you, then there may be disciplinary measures available (which I would argue would be harsh and counter-productive) but equally you could just accept that he isn't cut out for certain tasks.

Talking to the guy will be one of your first ports of call. You might find that he lacks confidence or insight. You might also find that he is very responsive and will appreciate the opportunity to improve himself.


答:
I would be inclined to say that gettext is a decent tool for the job, if you do it right. Doing it right means splitting the document to bite-sized chunks, usually paragraphs. See how po4a works. That way the translators only re-translate those parts of the document that have changed.

Generally keeping translated documents up-to-date is quite a bit of work however you do it. I have not heard about any method significantly better than po4a and using one translation system for all your needs has some benefits of your own.

Title: Is gettext appropriate for internationalizing user help documentation?

Body:
On my project, we have po files to internationalize/translate various labels, error messages, button-text etc. We also have separate po files for the entirety of our help documentation, which is included in the product.

Is this an appropriate use of gettext - putting entire documents in po files as opposed to just labels and messages?

The format has been made all the more complicated because sometimes (for tooltips or "what's this" icons) only a small part of the help doc is needed, resulting in single phrases/paragraphs being entries in the po file, which are then concatenated together when the user views the help... making the actual act of translation challenging.

Is there a better way to internationalize end user help documentation?


答:
Make sure the employee knows how important communication skills are to his job description.  Work with him/her to improve.

Don't insist that they be as good as the other team members at such tasks.

Assign tasks according to the principles you believe in.  Find a balance between efficient assignment of tasks to skills, and fairness/fun.

These are just summary ideas, hopefully someone will steal these points and fold them into one of the other answers.  ;-)


问:
How to calculate the checksum for Laboratory Information System (LIS) frames?
I am developing instrument driver and I want to know how to calculate checksum for a Laboratory Information System (LIS) frame.

Explanation:

Expressed by characters [0-9] and [A-F].

Characters beginning from the character after [STX] and until [ETB] or [ETX] (including  [ETB] or [ETX]) are added in binary.

The 2-digit numbers, which represent the least significant 8 bits in hexadecimal code,   are converted to ASCII characters [0-9] and [A-F].

The most significant digit is stored in CHK1 and the least significant digit in CHK2.

This is sample frame :

```<code><STX>2Q|1|2^1||||20011001153000<CR><ETX><CHK1><CHK2><CR><LF>
</code>```

and I want to know what is value of chk1 and chk2 and I am new in this so I am totally blank about how to calculate checksum

I am not getting above 3rd and 4th point.

Can anyone provide sample code for c#?

答:
Speaking as someone who has developed an entire LIS communication protocol from serial driver to strongly typed entities for a machine used in hundreds of different labs.

I've come to a lot of conclusions (short list):

The LIS Spec is bullshit (every LIS vendor has their own implementation which differs from every other) every hospital/lab LIS differs in the way the handshaking is written.

The Frame "Checksum" is nothing more than a stupid calculation which is meant to make people who wrote the spec feel better (it is in no way a good checksum as it can be easily overcome)

Whoever wrote the "State Machine" documentation for the LIS spec was a hack. As it does not properly convey any state nor transition (it is best to extrapolate your own stat machine than try to make sense of the drawing)

That being said:

http://www.hendricksongroup.com/code_003.aspx

Is a really simple example of how to calculate a checksum for an LIS frame.

If you are writing an LIS Driver my advice to you is to get LOTS of logs from the vendor (so that you may see exactly the communication taking place) you are connecting to and write LOTS of unit tests to match those logs, (that and if it needs to be for more than one vendor to make it EXTREMELY flexible). Oh and add lots of logging for yourself.


问:
What is the order of diagram drawing in a design?
I'm new with OOP and UML and I have some confusion here. I'd like to know where to start, I mean, somebody comes to you and ask you to do something (involves software design of course), once you have determined what has to be done, what is the order in which you have to start the software architecture? I mean, is it first the use case diagram or the class diagram? or should I draw some diagrams in parallel?

But basically, where should I start? and what UML diagram goes first? Thanks for helping!!

答:
There is not a rigid rule, but, some guidelines.

Most developers / analysts  will start, depending on the scenario.

A lot of analysts get started with the "use cases" diagrams, and eventually, add other diagrams, usually architectural diagrams, like packages or components.

And, then, with "Classes", "Activity", "Sequence" diagrams.

Cheers.


问:
Is it ok to replace optimized code with readable code?
Sometimes you run into a situation where you have to extend/improve some existing code. You see that the old code is very lean, but it's also difficult to extend, and takes time to read.

Is it a good idea to replace it with modern code?

Some time ago I liked the lean approach, but now, it seems to me that it's better to sacrifice a lot of optimizations in favor of higher abstractions, better interfaces and more readable, extendable code.

The compilers seem to be getting better as well, so things like struct abc = {} are silently turned into memsets, shared_ptrs are pretty much producing the same code as raw pointer twiddling, templates are working super good because they produce super lean code, and so on.

But still, sometimes you see stack based arrays and old C functions with some obscure logic, and usually they are not on the critical path.

Is it a good idea to change such code if you have to touch a small piece of it either way?

答:
Where?

On a home page of a Google-scale website, it is not acceptable. Keep the things as quick as possible.

In a part of an application which is used by one person once a year, it is perfectly acceptable to sacrifice performance in order to gain code readability.

In general, what are the non-functional requirements for the part of the code you're working on? If an action must perform under 900 ms. in a given context (machine, load, etc.) 80% of the time, and actually, it performs under 200 ms. 100% of the time, sure, make the code more readable even if it might slightly impact the performance. If on the other hand the same action never performed under ten seconds, well, you should rather try to see what's wrong with the performance (or the requirement in the first place).

Also, how readability improvement will decrease the performance? Often, developers are adapting the behavior close to premature optimization: they are afraid to increase the readability, believing that it will drastically destroy the performance, while the more readable code will spend a few microseconds more doing the same action.


答:
In general, you should focus on readability first, and performance much later. Most of the time, those performance optimizations are negligible anyway, but the maintenance cost can be huge.

Certainly all the "little" things should be changed in favor of clarity since, as you pointed out, most of them will get optimized by the compiler anyway.

As for the larger optimizations, there might be a chance that the optimizations are actually critical to reaching reasonable performance (though this isn't the case surprisingly often). I would make your changes and then profile the code before and after the changes. If the new code has significant performance issues, you can always roll-back to the optimized version, and if not you can just stick with the cleaner code version.

Change only one part of the code at a time and see how it affects performance after each round of refactoring.

Title: Is it ok to replace optimized code with readable code?

Body:
Sometimes you run into a situation where you have to extend/improve some existing code. You see that the old code is very lean, but it's also difficult to extend, and takes time to read.

Is it a good idea to replace it with modern code?

Some time ago I liked the lean approach, but now, it seems to me that it's better to sacrifice a lot of optimizations in favor of higher abstractions, better interfaces and more readable, extendable code.

The compilers seem to be getting better as well, so things like struct abc = {} are silently turned into memsets, shared_ptrs are pretty much producing the same code as raw pointer twiddling, templates are working super good because they produce super lean code, and so on.

But still, sometimes you see stack based arrays and old C functions with some obscure logic, and usually they are not on the critical path.

Is it a good idea to change such code if you have to touch a small piece of it either way?


答:
Usually, no.

Changing the code can cause unforeseen knock-on issues elsewhere in the system (which can sometimes go unnoticed until much later in a project if you don't have solid unit and smoke tests in place). I usually go by "if it ain't broke, don't fix it" mentality.

The exception to this rule is if you're implementing a new feature that touches this code. If, at that point, it doesn't make sense and refactoring really needs to take place, then go for it as long as refactoring time (and sufficient testing and buffer for dealing with knock-on issues) is all accounted for in estimates.

Of course, profile, profile, profile, especially if it's a critical path area.


问:
How do I completely-self-study Computer Science?
Being a completely self taught programmer, I would like it if I could better myself by self-learning the computer science course taught to a typical CS grad.

Finding different resources on internet has been easy, there is of course MIT open course ware, and there are Coursera courses from Stanford and other universities. There are numerous other open resources scattered around the Internet and some good books that are repeatedly recommended.

I have been learning a lot, but my study is heavily fragmented, which really bugs me. I would love If somewhere, I could find a path I should follow and a stack I should limit myself to, so that I can be sure about what essential parts of computer science I have studied, and then systematically approach those I haven't.

The problem with Wikipedia is it doesn't tell you what's essential but insists on being a complete reference.

MIT open course ware for Computer science and Electrical Engg. has a huge list of courses also not telling you what courses are essential and what optional as per person's interest/requirement. I found no mention of an order in which one should study different subjects.

What I would love is to create a list that I can follow, like this dummy one

```<code>SUBJECTS                                                        DONE

Introduction to Computer Science                                  *
Introduction to Algorithms                                        *
Discrete Mathematics
Adv. Discrete Mathematics
Data structures                                                   *
Adv. Algorithms
...
</code>```

As you can clearly see, I have little idea of what specific subjects computer science consists of.

It would be hugely helpful, even if someone pointed out essential courses from MIT Course ware ( + essential subjects not present at MIT OCW) in a recommended order of study.

I'll list the Posts I already went through (and I didn't get what I was looking for there)

https://softwareengineering.stackexchange.com/questions/49557/computer-science-curriculum-for-non-cs-major - top answer says it isn't worth studying cse

https://softwareengineering.stackexchange.com/questions/110345/how-can-a-self-taught-programmer-learn-more-about-computer-science - points to MIT OCW

https://softwareengineering.stackexchange.com/questions/49167/studying-computer-science-what-am-i-getting-myself-into

https://softwareengineering.stackexchange.com/questions/19912/overview-of-computer-science-programming

答:
Try the 2001 Computer Science curriculum recommendations from ACM/IEEE, linked here:
http://www.acm.org/education/curricula-recommendations

along with the 2008 CS updates.

Page 17 of the 2001 report has a handy chart which underlines all the "core" knowledge and still lists electives.

An undergraduate program wouldn't have time to cover even the courses considered core by these recommendations, so they will lump some of the categories together and let the students pick amongst them (eg, Operating Systems, Programming Languages, and Software Engineering get lumped into Software, and students pick a track).

You can find the required coursework on the CS department website for pretty much any school, and they should be some version of this.


答:
Although I would agree that there is no hard and fast rule, I have come up with a rough outline of steps after reading Martin Fowler's book on UML.

1) Analyse the actors first ( a uml diagram on the actors and how they interact with the system )

2) Use-Case Diagrams

3) Analyzing external factors that would impact a system ( not really a diagram just including for information sake )

4) Analyzing risks in the systems and estimating their impact ( again not really a diagram )

5) Sequence Diagrams ( with data-flow in them )

6) Class Diagrams

From the book:
"with a big system...It is easier ...to arrive at the list of actors first, and then ...the use cases for each actor."~Martin Fowler - UML Distilled

Recommend that book as a nice introduction to diagrams.

One more advice from the book: its better to have a few diagrams that you keep updated rather than having lots of diagrams that are least updated

Title: What is the order of diagram drawing in a design?

Body:
I'm new with OOP and UML and I have some confusion here. I'd like to know where to start, I mean, somebody comes to you and ask you to do something (involves software design of course), once you have determined what has to be done, what is the order in which you have to start the software architecture? I mean, is it first the use case diagram or the class diagram? or should I draw some diagrams in parallel?

But basically, where should I start? and what UML diagram goes first? Thanks for helping!!


问:
For what problems is object oriented programming not a good choice?
Somewhat inspired by this question: For what common problems is functional programming not a good fit? - but nevertheless a question which I always wanted, but was too afraid to ask.

I've been in ... well, let's call it engineering software development practically all my life, and in all that time, although OO had always been there (well, most of that time) I've never had the need to use "its ways", nor to learn that paradigm. We've always used rather simple program structures, routines/functions/modules and although it is opposite to today's best practices managing those programs (programs up to roughly 300k LOC, nothing too big) never proved to be difficult, let alone impossible.

So I wanted to ask you, what would be the sorta problems for which object oriented paradigm would not be a good choice? In comparison to procedural programming ?

答: The main value of OO is that it provides decoupling among components of your system, making it easier to write DRY code and adapt to specific types of change that you plan for in your design.  The cost is that it adds layers of indirection, which can make the code harder to reason about, less efficient and harder to modify in unanticipated ways (the ways that aren't aided by the decoupling your design provides).  It is therefore a waste of time for any subproblem where you don't need the decoupling it provides.  Specifically, it is a waste of time if you can easily write DRY code without it and don't anticipate any specific requirement changes that would benefit from the strong decoupling that OO provides.


答:
It's probably not a good idea to touch it - if the code was written that way for performance reasons, it means that changing it could bring back performance issues that had been previously solved.

If you do decide to change things to be more readable and extendable: Before you make a change, benchmark the old code under heavy load. Even better if you can find an old document or trouble ticket describing the performance issue that this odd-looking code is supposed to fix. Then after you make your changes, run the performance tests again. If it's not very different, or still within acceptable parameters, then it's probably OK.

It may sometimes happen that when other parts of a system change, this performance-optimised code no longer needs such heavy optimisations, but there's no way to know that for certain without rigorous testing.


问:
Generalise variable usage inside code
I would like to know if it is a good practice to generalize variables (use single variable to store all the values).

Consider simple example

```<code> Strings querycre,queryins,queryup,querydel;
    querycre = 'Create table XYZ ...';
    execute querycre ;
    queryins = 'Insert into XYZ ...';
    execute queryins ;
    queryup  = 'Update  XYZ set ...';
    execute queryup;
    querydel = 'Delete from XYZ ...';
    execute querydel ;
</code>```

and

```<code> Strings query;
    query= 'Create table XYZ ... ';
    execute query ;
    query= 'Insert into XYZ ...';
    execute query ;
    query= 'Update  XYZ set ...';
    execute query ;
    query= 'Delete from XYZ ...';
    execute query ;
</code>```

In first case I use 4 strings each storing data to perform the actions mentioned in their suffixes.

In second case just 1 variable to store all kinds the data.

Having different variables makes it easier for someone else to read and understand it better. But having  too many of them makes it difficult to manage.

Also does having too many variables hamper my performance?

P.S: please don't answer w.r.t the code in example it was just to convey what I really mean.

答:
In the example, I'd go with the second example.  It's quite clear to both a reader and optimizers what you are doing.  The first example is a bit more proper, and with somewhat more complicated code I'd use it, but do it like:

```<code>{
    String query = 'Create table XYZ ...';
    execute query;
}
{
    String query = 'Insert table XYZ ...';
    execute query;
}
And so on...
</code>```

(At this point, I might consider tdammers's solution.)

The problem with the first example is that querycre is in scope for the whole block, which might be extensive.  This can confuse someone reading the code.  It can also confuse the optimizers, which might leave in an unnecessary memory write so querycre is available later if needed (which it's not).  With all the braces, query is stored only in a register, if that.

With phrases like "Create table" and "execute" it doesn't look to me like an extra memory write is going to be noticed here, so I'd only fault the code for confusing the reader.  But it's handy to be aware of this if you're writing code where speed does matter.

Title: Generalise variable usage inside code

Body:
In the example, I'd go with the second example.  It's quite clear to both a reader and optimizers what you are doing.  The first example is a bit more proper, and with somewhat more complicated code I'd use it, but do it like:

{
    String query = 'Create table XYZ ...';
    execute query;
}
{
    String query = 'Insert table XYZ ...';
    execute query;
}
And so on...

(At this point, I might consider tdammers's solution.)

The problem with the first example is that querycre is in scope for the whole block, which might be extensive.  This can confuse someone reading the code.  It can also confuse the optimizers, which might leave in an unnecessary memory write so querycre is available later if needed (which it's not).  With all the braces, query is stored only in a register, if that.

With phrases like "Create table" and "execute" it doesn't look to me like an extra memory write is going to be noticed here, so I'd only fault the code for confusing the reader.  But it's handy to be aware of this if you're writing code where speed does matter.


答:
if profiling shows that the optimization is unneeded (it is not in a critical section) or even has a worse runtime (as a result of bad premature optimization) then sure replace with the readable code that is easier to maintain

also make sure the code behaves the same with the appropriate tests


问:
Testing applications with statistical features

Possible Duplicate:

  How should I test randomness?

Are their some techniques described for testing applications that have as a requirement some statistical or probabilistic features? They may for example use some random number generators and the customer may wish certain distribution etc.

How would software companies test that the statistical requirements are satisfied?

答:
All of the properties you mention are deterministic properties. You can assert that your statistical methods are consistent given known inputs/outputs. Likewise, random number generation is still deterministic given the seed.

You would do unit/integration testing like you would any other code (the Right BICEP, CORRECT Boundary Conditions, etc.). Functionally, there is no difference.


答:
It depends on why the code was optimized and what the effect of changing it would be and what the impact of the code on overall performance might be. It should also depend on whether you have a good way to load test changes.

You should not make this change without profiling before and after and perferably under a load that is similar to what would be seen on production. That means not using a tiny subset of data on a developer machine or testing when only one user is using the system.

If the optimization was recent, you may be able to talk to the developer and find out exactly what the issue was and how slow the application was before the optimization. This can tell you a lot about whether it is worth it to do the optimizing and what conditions the optimization was needed for (a report that covers a whole year for instance may not have become slow until Sept or Oct, if you are testing your change in February, the slowness might not yet be apparent and the test invalid).

If the optimization is rather old, newer methods might even be faster as well as more readable.

Ultimately this is a question for your boss. It is time-consuming to refactor something that has been optimized and to make sure that the change didn't affect the end result and that it performs as well or at least acceptably compared to the old way. He may want you to spend your time in other areas instead of taking on a high risk task to save a few minutes of coding time. Or he may agree that the code is hard to understand and has needed frequent intervention and that better methods are now available.


答:
In addition to SnOfus's answer, remember that even though you are dealing with statistical/probabilistic quantities, there are still some completely deterministic properties you can test for. For example, certain distributions (like the exponential) distribution are always positive. If such a distribution starts returning negative numbers, you've a problem. Same things go for bounded or discrete distributions. </p>

<p>Always look at the problem and see what needs to be done, regardless of higher maths that might be involved. </p>

Title: Testing applications with statistical features

Body:
Possible Duplicate:

  How should I test randomness?

Are their some techniques described for testing applications that have as a requirement some statistical or probabilistic features? They may for example use some random number generators and the customer may wish certain distribution etc.

How would software companies test that the statistical requirements are satisfied?

Body:
In addition to SnOfus's answer, remember that even though you are dealing with statistical/probabilistic quantities, there are still some completely deterministic properties you can test for. For example, certain distributions (like the exponential) distribution are always positive. If such a distribution starts returning negative numbers, you've a problem. Same things go for bounded or discrete distributions.

Always look at the problem and see what needs to be done, regardless of higher maths that might be involved.


答:
I would go for the first one, for readability/debugging/testing, etc. You can avoid the global namespace cluttering issue by simply creating a local namespace for all the functions on your page. I use object notation style, as recommended by Paul Irish (see slides 13-15 on http://paulirish.com/2009/perf/)</p>

```<code>var MYPAGE = {
  onReady : function(){
  // init code
  },
  someOtherCallback : function(){}
};

jQuery(document).ready(MYPAGE.onReady);
</code>```

Body:
I would go for the first one, for readability/debugging/testing, etc. You can avoid the global namespace cluttering issue by simply creating a local namespace for all the functions on your page. I use object notation style, as recommended by Paul Irish (see slides 13-15 on http://paulirish.com/2009/perf/)

var MYPAGE = {
  onReady : function(){
  // init code
  },
  someOtherCallback : function(){}
};

jQuery(document).ready(MYPAGE.onReady);


问:
When/why is it easier to beg forgiveness than ask permission?
The saying "It's easier to beg forgiveness than ask permission" seems pretty popular among programmers and IIRC was attributed to Grace Hopper.  In what situations is this typically true, and why do you believe that such a counterintuitive proposition would hold?</p>

答:
It's politics, all politics.

I've seen this become a reality on occasion, when the management or client put up too many barriers to simple changes (e.g. "quality" reviews by people who know nothing about the system, needing to get signoff from too many business areas) that it's sometimes quicker and easier to just "rip off the bandage": don't tell too many people, just make the change, and if it works, everyone's happy, you might get a slap on the wrist for "not following the process", etc.

Of course, if the change fails, you might find even more processes being layered on... but that's the risk you took.

(disclaimer: I have no problems with quality controls and checks and balances - as long as they're reasonable)


答:
Think of it from a business perspective. What are the costs of the change? How much time do you need to make the change and how much will you save in the long run by making the code more easy to extend or maintain? Now attach a price tag to that time and compare it to the money lost by reducing performance. Maybe you need to add or upgrade a server to make up for the lost performance. Maybe the product does no longer meet the requirements and cannot be sold anymore. Maybe there is no loss. Maybe the change increases robustness and saves time elsewhere. Now make your decision.

On a side note, in some cases it might be possible to keep both versions of a fragment. You could write a test generating random input values and verify the results with the other version. Use the "clever" solution to check the result of a perfectly understandable and obviously correct solution and thereby gain some reassurance (but no proof) that the new solution is equivalent to the old one. Or go the other way round and check the result of the tricky code with the verbose code and thereby documenting the intention behind the hack in an unambiguous manner.


问:
Suggestions for a CMS markup language for PHP
As a learning experience, and as project, I am attempting to write a CMS module for ZF2. One of the functionality I would like to have is the possibility of adding dynamic contents in the pages by calling PHP functions in the view scripts.

However, I do not want to give the users freedom in writing PHP code directly inside the page content, but rather implement custom view helpers (or widgets) to handle logic. For example: calling partial, partialLoop, url, etc. specifying arguments and all.

I liked the idea of extending Markdown but this would get complicated when trying to add custom CSS class to elements, etc.

Then I had the idea of simply doing a preg_replace on some patterns. For example, the string :

```<code>### partialLoop:['partials/display.phtml',[{id:'p1',price:4.99},{id:'p2',price:12.34}]] ###
</code>```

would be replaced by

```<code><?php echo $this->partialLoop('partials/display.phtml', array(array('id'=>'p1','price'=>4.99),array('id'=>'p2','price'=>12.34))) ?>
</code>```

Obviously, there would be some caching done so the page content is not rendered everytime. Does this sound good?

If not, what would be a good way of doing this? Or is there a project already being developed for doing this? (I'd like to avoid heavy third party libs and something fairly or fully compatible with ZF2 would be nice.)

Thanks.

答: You should check out a template library called Twig. It would integrate well with ZF2 (many people have done it) and you can extend it to do anything you want or to limit anything you want.</p>


答:
Expecting that everyone will have the same communication skills is as rational as expecting you'll teach the crippled man to run as fast as the rest of the team.

People are different, they have different skills and different weakness. Firing a great programmer just because he can't catch up with the others in communication skills would be like firing a crippled man because he can't walk as fast as the others. It would be unfair from ethical point of view and it will be against your own economical interests - to get the job done.

You should at first, if you've failed to do that in the past, read about the Asperger syndrome. Poor social skills are the major indicator of that syndrome.

Second, you can hire and fire whoever you want, but if you fail to cope with the strenghts and weaknesses of your employees, you'll end up with a bunch of average programmers, because the best will leave (if not get fired first).

There is a film, Adam, in which the genial programmer is fired just because he have written something he wasn't expected to. His idea could bring a lot of money to the employer, but he couldn't use the chance because he was concentrated on his "principles".


答:
The problem here is distinguishing "optimized" from readable and extendable, what we as users see as optimized code and what the compiler sees as optimized are two different things.  The code you're looking at changing might not be a bottleneck at all, and therefore even if the code is "lean" it's not even needed to be "optimized".  Or if the code is old enough, there might be optimizations made by the compiler to built-ins that makes using a newer simple built-in structure equally or more efficient than the old code.

And "lean," unreadable code isn't always optimized.

I used to be of the mindset that clever/lean code was good code, but sometimes taking advantage of obscure rules of the language hurt rather than help in code creation, I've been bitten more oft than not in any embedded work when trying to be clever because the compiler makes your clever code into something utterly unusable by the embedded hardware.


问:
Is there a phrase or word to describe an algorithim or program is complete in that given any value for its arguments there is a defined outcome?
Is there a phrase or word to describe an algorithm or program is complete in that given any value for its arguments there is a defined outcome? i.e. all the ramifications have been considered whatever the context?

A simple example would be the below function:

```<code>function returns string get_item_type(int type_no)
{
  if(type_no < 10)
    return "hockey stick"
  else if (type_no < 20)
    return "bulldozer"
  else
    return "unknown"
}
</code>```

(excuse the dismal pseudo code)

No matter what number is supplied all possibilities are catered for. My question is: is there a word to fill the blank here:

```<code>"get_item_type() is ______ complete"
</code>```

?

(The answer is  not Turing Complete - that is something quite different - but I annoyingly always think of something as "Turing Complete" when I am thinking of the above).

答:
Mathematically speaking, the term you are looking for is "Total Function" (a function that is defined for every possible value in some domain), as opposed to a "partial function", which is only defined for a subset of the possible input values.

Note that, strictly speaking, mathematical functions are always total on their own domain; calling a function "partial" only makes sense if you offset it against another domain, such as the function f(x) = 1/x: the domain of this function is the domain of all real numbers except zero, but against the domain of all real numbers (including zero), it is partial.

In programming, the types of a function's inputs state a domain already, and by not defining the function for all of them, you could say that the function is partial. However, many programming languages fall back to a default behavior when you don't explicitly return anything - they may return 0, null, undefined, etc. Technically speaking, such functions are still total - they return a value for all possible inputs -, but conceptually, there are gaps in the definition. And not all programming languages feature such fallbacks; the alternatives are refusing to compile, responding with "undefined behavior", raising an exception, etc.

BTW, note that neither determinism nor purity have anything to do with this. A deterministic function is one that always has the same effect given the same context (relevant system state and inputs); a pure function is a function that does not have any side effects (so that it always returns the same value given the same inputs, regardless of any outside state, and without influencing outside state in any way). You can easily come up with a function that is partial, yet fully deterministic (provided that partial functions are legal in your programming language, and definition gaps are handled in a predicatable way); and conversely, if you manage to write a non-deterministic function, e.g. by reading from a hardware entropy source, there is no reason why it would have to be total (nor partial). The same goes for purity, unless a definition gap automatically introduces side effects (then all pure functions must also be total).


问:
Should I avoid SharePoint Development in Visual Studio?
Not long ago I started an internship at a company that supplies SharePoint consultancy, hosting and development. While their consultancy seems to be pretty good and solid, I feel their development department lacks direction. The reason for this, most likely, is that they stopped outsourcing not too long ago.

One thing that I've frequently bumped my head into is the following:

My supervisor strongly insists that everything that can be done natively in SharePoint (somehow this includes editing xslt files in Designer) should be done in SharePoint. Even if this results in longer development time (at least when they make me write XSLT) and reduced usability.

Her main arguments for this are:

Better maintainability

Editing the functionality doesn't require programming knowledge

I feel the company is a little biassed and I am unable to get a decent discussion going. This is why I am looking for other places to get some responses on the subject (and not only on the arguments of my supervisor, but more on the subject in general).

Kind regards

答: Even if you don't plan on writing custom event handlers, web pages, etc. you should consider using Visual Studio for the reasons Phil Duffy gives - it is much easier to manage code and, in the case of XML, easier to edit in Visual Studio than in SharePoint designer or NotePad for that matter.</p>

OwnerDisplayName: SaphuA


答: Because once something is done, as long as it doesn't make things worse, it's often easier to leave it in than to take it out (i.e. "what's done is done.")</p>

Title: When/why is it easier to beg forgiveness than ask permission?

Body: The saying "It's easier to beg forgiveness than ask permission" seems pretty popular among programmers and IIRC was attributed to Grace Hopper.  In what situations is this typically true, and why do you believe that such a counterintuitive proposition would hold?</p>


答:
Basically, you are asking if refactoring is a worthwhile venture.  The answer to this is most certainly yes.

But...

...you need to do it carefully.  You need solid unit, integration, functional, and performance tests for any code you are refactoring.  You need to be confident that they really do test all required functionality. You need the ability to run them easily and repeatedly.  Once you have that, you should be able to replace components with new components containing the equivalent functionality.

Martin Fowler wrote the book on this.


答:
Performance is everything. Give him the programming tasks. Do talk this over with the rest of the department. Optionally bring someone in to do com tasks or task someone on com tasks only. Don't think of the programming of having fun. Everything is "fun" from your POV.

If you don't you will create a situation that's extremely hard to manage and less effective than it could be.


答:
What a great question, it is the kind of thing all team lead, supervisor, managers of techies should think about. I like your approach, everyone should get a 'fun' task. Taking it further having a team that can pickup different tasks and is cross trained prevents the Peterbilt Principle from causing havoc 'indesipensible team member leaves team or even takes gasp a vacation'.

Now, as pointed out by lots of posts, work is not fair and shouldn't be. Managers are measured on how much valuable work gets done.

Managers match tasks to individuals based on skills.

Good managers match tasks based on skills, growth, interest and building
productivity of the team.

Great managers get their team to do this with a little help and guidance. Ie without the manager spending all day on it.

Talk to your good programmer, ask him if there are things he wants to learn. What other tasks would he accept... even what is least objectionable to him.
Can he help other team members with their programming... mentor them. Yes I know communication is a problem, so maybe he should be working on that.

Another way to package this is having a list of tasks and let each staff member pick something. Let your good programmer pick first. If you warn him in advance and show him the list of tasks even better.

If you get resistence, which you almost always do with change, find a selling point, something of value to him, why will he benefit. Lastly you can just tell him to do it for the team.

Also expect mistakes and lower productivity to start, that’s a sign people are learning. This project may suffer, but the next will be better.

In closing, it is your job to make sure stuff gets done, but so is growing your staff and if you can engage them in the process even better. Some might say the best way to ensure stuff gets done is a team that knows what needs to get done and owns the results.

Edit: Oh and keep trying, the advice above comes from years of making mistakes, but I always knew I wanted to help my team grow, and I knew productivity is king, so I kept trying new things when the last attempt failed.


答:
You should not change working, production code without a good reason. "Refactoring" is not a good enough reason unless you cannot do your job without that refactoring. Even if what you are doing is fixing bugs within the difficult code itself, you should take the time to understand it, and make the smallest possible change. If the code is that hard to understand, you won't be able to understand it completely, and so any changes you make will have unpredictable side effects-- bugs, in other words. The bigger the change, the more likely you are to cause trouble.

There would be an exception to this: if the incomprehensible code had a complete set of unit tests, you could refactor it. Since I have never seen or heard of incomprehensible code with complete unit tests, you write the unit tests first, obtain the agreement of the necessary people that those unit tests do in fact represent what the code should be doing, and THEN make the code changes. I've done that once or twice; it's a pain in the neck, and very expensive, but does produce good results in the end.


问:
What options are there for splitting UI layout from code logic using a markup language?
What tools similar to GWT's UIBinder exist in other languages? By this I mean a system where you can define your UI layout in a markup language (preferably html+css) and attach the functionality to the layout using the code. I'm most interested in anything for python, but answers in other languages would interest me as well.

I'm interested because the benefits of having a non-programmer work directly on the layout without needing to touch the code and adjust a bunch of UI toolkit method calls is very productive.

I'm aware of Flex for flash, but is there anything else out there?

What search terms might I use to find such frameworks? I've looked around but I haven't found anything concrete.

Edit: I'm not only interested in web frameworks, but desktop applications as well.

Edit2: My question appears to be close to a duplicate of https://stackoverflow.com/questions/2962874/what-are-the-open-source-alternatives-to-wpf-xaml

答: Adobe Flex can deal with that.  If you are running under Air then you can call C style dlls from your Flex code if you need to.  </p>


答:
If it's just a short piece of code that does something relatively simple in a hard-to-understand way, I'd shift the "quick understanding" in an extended comment and/or an unused alternative implementation, like</p>

```<code>#ifdef READABLE_ALT_IMPLEMENTATION

   double x=0;
   for(double n: summands)
     x += n;
   return x;

#else

   auto subsum = [&](int lb, int rb){
          double x=0;
          while(lb<rb)
            x += summands[lb++];
          return x;
        };
   double x_fin=0;
   for(double nsm: par_eval( subsum
                           , partitions(n_threads, 0, summands.size()) ) )
     x_fin += nsm;
   return x_fin;

#endif
</code>```

Body:
If it's just a short piece of code that does something relatively simple in a hard-to-understand way, I'd shift the "quick understanding" in an extended comment and/or an unused alternative implementation, like

#ifdef READABLE_ALT_IMPLEMENTATION

   double x=0;
   for(double n: summands)
     x += n;
   return x;

#else

   auto subsum = [&](int lb, int rb){
          double x=0;
          while(lb<rb)
            x += summands[lb++];
          return x;
        };
   double x_fin=0;
   for(double nsm: par_eval( subsum
                           , partitions(n_threads, 0, summands.size()) ) )
     x_fin += nsm;
   return x_fin;

#endif


问:
Relationship between Repository and Unit of Work
I am going to implement a repository, and I would like to use the UOW pattern since the consumer of the repository could do several operations, and I want to commit them at once.

After read several articles about the matter, I still don't get how to relate this two elements, depending on the article it is being done in a way u other.

Sometimes the UOW is something internal to the repository:

public class Repository
{
    UnitOfWork _uow;

    public Repository()
    {
       _uow = IoC.Get<UnitOfWork>();
    }

    public void Save(Entity e)
    {
        _uow.Track(e);
    }

    public void SubmittChanges()
    {
        SaveInStorage(_uow.GetChanges());
    }
}
```

<p>And sometimes it is external:</p>

<pre class="lang-cs prettyprint-override"><code>public class Repository
{
    public void Save(Entity e, UnitOfWork uow)
    {
        uow.Track(e);
    }

    public void SubmittChanges(UnitOfWork uow)
    {
        SaveInStorage(uow.GetChanges());
    }
}
</code>```

Other times, is the UOW whom references the Repository

public class UnitOfWork
{
    Repository _repository;

    public UnitOfWork(Repository repository)
    {
       _repository = repository;
    }

    public void Save(Entity e)
    {
        this.Track(e);
    }

    public void SubmittChanges()
    {
       _repository.Save(this.GetChanges());
    }
}
```

How are these two elements related? UOW tracks the elements that needs be changed, and repository contains the logic to persist those changes, but... who call who? Does the last make more sense?

Also, who manages the connection? If several operations have to be done in the repository, I think using the same connection and even transaction is more sound, so maybe put the connection object inside the UOW and this one inside the repository makes sense as well.

Cheers

答:
The methods are most commonly given to the UOW interface (which is normally constructed via a factory).

You typically call methods on a UOW interface from command pattern class(es) / facade.  Since UOW simply defers database IO until later (to prevent you from having long-running transactions or multiple calls to the database that may be unnecessary), working with the UOW should be at the same level that you would normally work with your database.

Microsoft has a very thorough post on the UOW pattern:

http://msdn.microsoft.com/en-us/magazine/dd882510.aspx


答:
In Brief: it Depends

Are you really going to need or use your refactored / enhanced version?

Is there a concrete gain, immediate or long-term?

Is this gain only for maintainability, or really architectural?

Does it really need to be optimized?

Why?

What target gain do you need to aim for?

In Details

Are you going to need the cleaned up, shiny stuff?

There are things to be cautious about here, and you need to identify the limit between what is real, measurable gain and what is just your personal preference and potential bad habit of touching code that shouldn't be.

More specifically, know this:

There is such a thing as Over-Engineering

It's an anti-pattern, and it comes with issues built-in:

it may be more extensible, but it may not be easier to extend,

it may not be simpler to understand,

last, but definitely not least here: you might slow down the whole code.

Some could also mention the KISS principle as a reference, but here it's counter-intuitive: is the optimized way the simple way or the cleany architectured way? The answer is not necessarily absolute, as explained in the rest below.

You Ain't Gonna Need It

The YAGNI principle is not completely orthogonal with the other issue, but it helps to ask yourself the question: are you going to need it?

Does the more complex architecture really present a benefit for you, apart from giving the appearance of being more maintainable?

If It Ain't Broke, Don't Fix It

Write this on a big poster and hang it next to your screen or in the kitchen area at work, or in the dev meeting room. Of course there are a lot of other mantras that are worth repeating yourself, but this particular one is important whenever you try to do "maintenance work" and feel the urge to "improve" it.

It's natural for us to want to "improve" code or even just touch it, even unconsciously, as we read through it to try to understand it. It's a good thing, as it means we're opinionated and try to get a deeper understanding of the internals, but it's also bound to our skill-level, our knowledge (how do you decide what's better or not? well, see sections below...), and all the assumptions we make about what we think we know the software...:

actually does,

actually needs to do,

will eventually need to do,

and how well it does it.

Does it really need to be optimized?

All this said, why was it "optimized" in the first place? They say that premature optimization is the root of all evil, and if you see undocumented and seemingly optimized code, usually you could assume it probably didn't follow the Rules of Optimization didn't dearly need the optimization effort and that it was just the usual developer's hubris kicking in. Yet again, maybe it's just yours talking now.

If it does, within which limits does it become acceptable? If there's a need for it, this limit exists, and gives you room to improve things, or a hard-line to decide to let it go.

Also, beware of invisible characteristics. Chances are, your "extensible" version of this code will you up more memory at runtime as well, and present even a larger static memory footprint for the executable. Shiny OO features come with unintuitive costs like these, and they may matter to your program and the environment it's supposed to run on.

Measure, Measure, Measure

As the Google folks now, it's all about data! If you can back it up with data, then it's necessary.

There's this not so old tale that for every $1 spent in development it will be followed by at least $1  in testing and at least $1 in support (but really, it's a lot more).

Change impacts a lot of things:

you might need to produce a new build;

you should write new unit tests (definitely if there were none, and your more extensible architecture probably leaves room for more, as you have more surface for bugs);

you should write new performance tests (to make sure this stays stable in the future, and to see where the bottlenecks are), and these are tricky to do;

you'll need to document it (and more extensible means more room for details);

you (or someone else) will need to extensively re-test it in QA;

code is (almost) never bug-free, and you'll need to support it.

So it's not just hardware resources consumption (execution speed or memory footprint) that you need to measure here, it's also team resources consumption. Both need to be predicted to define a target aim, to be measured, accounted for, and adapted based on development.

And for you manager, that means fitting it into the current development plan, so do communicate about it and do not get into furious cow-boy/submarine/black-ops coding.

In General...

Yes, but...

Don't get me wrong, in general, I'd be in favor of doing why you suggest, and I often advocate it. But you need to be aware of the long-term cost.

In a perfect world, it's the right solution:

computer hardware get better over time,

compilers and runtime platforms get better over time,

you get close-to-perfect, clean, maintainable and readable code.

In practice:

you may make it worse

You need more eyeballs to look at it, and the more you complexify it, the more eyeballs you need.

you can't predict the future

You can't know with absolute certainty if you'll ever need it and not even if the "extensions" you'll need would have been easier and quicker to implement in the old form, and if themselves would need to be super-optimized.

it represents, from management's perspective, a huge cost for no direct gain.

Make it Part of the Process

You mention here that it's a rather small change, and you have some specific issues in mind. I'd say it's usually OK in this case, but most of us also have personal stories of small changes, almost surgical-strike edits, which eventually turned into maintenance nightmare and nearly-missed or exploded deadlines because Joe Programmer didn't see one of the reasons behind the code and touched something that shouldn't have been.

If you have a process to handle such decisions, you take the personal edge off of them:

If you test things correctly, you'll know quicker if things are broken,

If you measure them, you'll know if they improved,

If you review it, you'll know if it throws people off.

Test Coverage, Profiling and Data-Collection are Tricky

But, of course, your testing code and metrics might suffer from the same issues you're trying to avoid for your actual code: do you test the right things, and are they the right thing for the future, and do you measure the right things?

Still, in general, the more you test (until a certain limit) and measure, the more data you collect and the safer you are. Bad analogy time: think of it like driving (or life in general): you can be the best driver in the world, if the car breaks down on you or someone decided to kill themselves by driving into your car with their own today, your skills might not be enough. There are both environmental things that can hit you, and human errors also matter.

Code Reviews are the Development Team's Hallway Testing

And I think the last part is key here: do code reviews. You won't know the value of your improvements if you make them solo. Code reviews are our "hallway testing": follow Raymond's version of the Linus' Law both for detecting bugs and detecting over-engineering and other anti-patterns, and to ensure that the code is in line with your team's abilities. There's no point in having the "best" code if nobody else but you can understand and maintain it, and that goes both for cryptic optimizations and 6-layers deep architectural designs.

As closing words, remember:

Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? - Brian Kernighan


问:
Is making my own copyright licence safe?
I've seen various open source libraries (actually I've seen it for assets as well) having a home-baked license in the following manner :

SomeGuy's License:
1. You can use this code freely in commercial projects and modify it as you wish, but not sell it
2.
  If you want to sell a modified version, drop me an email first, or give credits to me

Edit:

The above example is ambiguous, so I am giving another one, I want to know if 3 lines of license will hold some ground:

SomeGuy's License:
1. You can use this code in a commercial project as a 3rd party library
2.
  You can't sell it as a derivative work

I know that such license is not polished at all, for example the Creative Commons set of licenses seem to be short, but actually have some large legal stuff underneath it, but I wonder if at least some level of protection can be gained with a hobby license like that ?

My question is, could this hold any ground in the court, or would the corporative lawyers of the company X tear it apart ?

答:
There are a number of good Open Source licenses at the Open Source Initiative. You would be best served by starting with one of those as a base and not trying to write your own from scratch.

It is very important that you include the standard non-indemnity clauses, such as this one from the MIT license:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

It would be good to stipulate non-erasure of copyright notice. If you have your name and email address in a copyright notice in every source file then you might at least get some advertising leverage from the pirates. A salaried programmer who works for a boss who violates copyright will usually leave the copyright notices in the source code.

If your software is any good people will copy it, in whole or in part, mangle it, and include it in their commercial products without notifying you or paying you anything. These infringements will never get to court because you wont be able to detect them. Welcome to life as we know it on this planet.

Your best protection is to offer downloads from an attractive site that offers your own commercial support for the software, and to publish updates from time-to-time, and to respond to email inquiries. Having well-known software is in itself a deterrent to violations.