答:
Fix them if they are crash/data loss bugs. Shipping a program with a known data-loss bug is downright malicious and inexcusable.

If the bug is cosmetical or non-critical (can be avoided) then it should be documented and a workaround should be provided. Ideally it should be fixed, but sometimes it's too expensive to fix it for the current release.

Notice how every bigger software project has a 'Known Issues' section in the ReadMe which usually lists exactly that: Bugs that are known.

Knowing Bugs and NOT communicating them is IMHO only acceptable for really minor/cosmetical bugs.

Title: Fix bugs, or wait for the customer to find them?

Body:
Do other people fix bugs when they see them, or do they wait until there's crashes/data loss/people die before fixing it?

Example 1

```<code> Customer customer = null;
 ...
 customer.Save();
</code>```

The code is clearly wrong, and there's no way around it - it's calling a method on a null reference. It happens to not crash because Save happens to not access any instance data; so it's just like calling a static function. But any small change anywhere can suddenly cause broken code that doesn't crash: to start crashing.

But, it's also not inconceivable that correcting the code:

```<code>Customer customer = null;
...
customer = new Customer();
try
   ...
   customer.Save();
   ...
finally
   customer.Free();
end;
</code>```

might introduce a crash; one not discovered through unit tests with complete coverage, and manual user testing.

Example 2

```<code>float speed = 0.5 * ((G * mass1 * mass2) / R) * Pow(time, 2);
</code>```

People knowing physics will recognize that it's supposed to be R2 in the denominator.

The code is wrong, it's absolutely wrong. And overestimating the speed will cause the retro-rockets to fire too soon, killing all the occupants of the spacecraft.

But it's also possible perhaps having it over-estimate the speed is masking another issue: the air-bags can't deploy while the shuttle is moving too fast. If we suddenly fix the code:

```<code>float speed = 0.5 * ((G * mass1 * mass2) / Pow(R, 2)) * Pow(time, 2);
</code>```

Now the speed is accurate, and suddenly airbags are deploying when they shouldn't.

Example 3

Here's an example that i had recently, checking if a string contains invalid characters:

```<code>if (StrPos(Address, "PO BOX") >= 0)
{
   //Do something
}
</code>```

What if it turns out there's a bug in the Do something branch? Fixing the obviously incorrect code:

```<code>if (StrPos("PO BOX", Address) >= 0)
{
   //Do something
}
</code>```

Fixes the code, but introduces a bug.

The way I see it there are two possibilities:

fix the code, and get blamed for breaking it

wait for the code to crash, and get blamed for having a bug

What do you politically do?

Example 4 - Today's real world bug

I am constructing an object, but calling the wrong constructor:

```<code>Customer customer = new Customer();
</code>```

Turns out that the "parameterless" constructor is actually an parameterized constructor from  further back in the inheritance chain:

```<code>public Customer(SomeObjectThatNobodyShouldBeUsingDirectly thingy = null)
public Customer(InjectedDependancy depends)
</code>```

Calling it is a mistake, since it bypasses all the subsequent constructors.

I could change the object's lineage to not expose such a dangerous constructor, but now I have to change the code to:

```<code>Customer customer = new Customer(depends);
</code>```

But I can't guarantee that this change won't break anything. Like my Example 1 above, perhaps someone, somewhere, somehow, under some esoteric conditions, depends on the constructed Customer to be invalid and full of junk.

Perhaps the Customer object, now that it is properly constructed will allow some code to run that previously never did, and now I can get a crash.

I can't bet your wife's life on it.

And I can test it from here to Tuesday, I can't swear on your daughter's life that I didn't introduce a regression.

Do I:

Fix the code and get blamed for breaking it? or

Leave the bug, and get blamed when the customer finds it?


问:
Does it work when a developer is the project manager's boss?
I am in the planning stage of a project and I am looking to hire a project manager. I would like to do some coding and keep eye on all parts of the project. However, i have a feeling that a project manager will get better results. I have the following options:
1) manage the project and not code
2) hire a project manager and code myself

I am worried that the project manager will feel impeded by having the project owner in the development team. If I run the project, the team might fall apart causing the project to fail. To stick within budget, I have to be involved in one capacity or another.

Does anyone have experience with this situation, any suggestions?

more info: 4 in-house developers each responsible for a specific area. The developers can also outsource work if agreed to by the project manager.

答:
I'd suggest you go on developing and hire a project manager.

In the company I work I've seen several ways of management. My boss is a programmer. He doesn't write code now, but he used to  for a long time. For some time he was trying to do all the management by himself, but this wasn't really a success.

Now he has hired project managers (two people), and the team works better now. He takes part in both technical and management discussions and sometimes prepares documents himself.

I also wouldn't worry about being in the development team and the boss at the same time. After all, you're going to hire someone professional, who must be able to work with any kind of people.

P.S. imho project management isn't very difficult to learn, especcailly when you work with a small team. Maybe some time after working with professional project managers, you will be able to do all the management yourself.

ContentLicense: CC BY-SA 3.0


问:
Why aren't more desktop apps written with Qt?
As far as I know and have understood in my experience with Qt, it's a very good and easy to learn library. It has a very well designed API and is cross-platform, and these are just two of the many features that make it attractive. I'm interested to know why more programmers don't use Qt. Is there a deficiency which speaks against it? Which feature makes other libraries better than Qt? Is the issue related to licensing?</p>

答:
I agree with nearly all of the reasons discussed above however a lot of people here have said they wouldn't use Qt because of the extra overhead that it brings with it. I disagree with that because all the most common languages today (Java, C# and Python) carry a fair bit of overhead themselves.

Secondly, Qt makes programming with C++ so easy and straight-forward that it makes up for the extra resources it uses. I've come across quite a few console applications written in Qt rather than standard C++ because of the ease in which they can be written.

I would say that the productivity of Qt is greater than that of C/C++ but less than languages like Python.


问:
My boss decided to add a "person to blame" field to every bug report. How can I convince him that it's a bad idea?
In one of the latest "WTF" moves, my boss decided that adding a "Person To Blame" field to our bug tracking template will increase accountability (although we already have a way of tying bugs to features/stories). My arguments that this will decrease morale, increase finger-pointing and would not account for missing/misunderstood features reported as bug have gone unheard.

What are some other strong arguments against this practice that I can use? Is there any writing on this topic that I can share with the team and the boss?

答:
Change "Person to blame" to "Person to praise"

The main person to fix the bugs gets their name on it.


答: Tell him "blame" is negative. Change it to "person to fix" then at least it is framed in a positive manner, and the same job still gets done. How can people work if they are being "blamed"?! </p>

Title: My boss decided to add a "person to blame" field to every bug report. How can I convince him that it's a bad idea?

Body:
In one of the latest "WTF" moves, my boss decided that adding a "Person To Blame" field to our bug tracking template will increase accountability (although we already have a way of tying bugs to features/stories). My arguments that this will decrease morale, increase finger-pointing and would not account for missing/misunderstood features reported as bug have gone unheard.

What are some other strong arguments against this practice that I can use? Is there any writing on this topic that I can share with the team and the boss?


问:
Reading graph inputs for a programming puzzle and then solving it
I just took a programming competition question and I absolutely bombed it. I had trouble right at the beginning itself from reading the input set. The question was basically a variant of this puzzle http://codercharts.com/puzzle/evacuation-plan but also had an hour component in the first line(say 3 hours after start of evacuation). It reads like this

This puzzle is a tribute to all the people who suffered from the earthquake in Japan. The goal of this puzzle is, given a network of road and locations, to determine the maximum number of people that can be evacuated.

The people must be evacuated from evacuation points to rescue points. The list of road and the number of people they can carry per hour is provided.

Input Specifications Your program must accept one and only one command line argument: the input file. The input file is formatted as follows: the first line contains 4 integers n r s t n is the number of locations (each location is given by a number from 0 to n-1) r is the number of roads s is the number of locations to be evacuated from (evacuation points) t is the number of locations where people must be evacuated to (rescue points) the second line contains s integers giving the locations of the evacuation points the third line contains t integers giving the locations of the rescue points the r following lines contain to the road definitions. Each road is defined by 3 integers l1 l2 width where l1 and l2 are the locations connected by the road (roads are one-way) and width is the number of people per hour that can fit on the road

Now look at the sample input set

```<code>5 5 1 2 3

0

3 4

0 1 10

0 2 5

1 2 4

1 3 5

2 4 10
</code>```

The 3 in the first line is the additional component and is defined as the number of hours since the resuce has started which is 3 in this case.

Now my solution was to use Dijisktras algorithm to find the shortest path between each of the rescue and evac nodes. Now my problem started with how to read the input set. I read the first line in python and stored the values in variables. But then I did not know how to store the values of the distance between the nodes and what DS to use and how to input it to say a standard implementation of dijikstras algorithm.

So my question is two fold 1.) How do I take the input of such problems? - I have faced this problem in quite a few competitions recently and I hope I can get a simple code snippet or an explanation in java or python to read the data input set in such a way that I can input it as a graph to graph algorithms like dijikstra and floyd/warshall. Also a solution to the above problem would also help.

2.) How to solve this puzzle? My algorithm was:

Find shortest path between evac points (in the above example it is 14 from 0 to 3)
Multiply it by number of hours to get maximal number of saves
Also the answer given for the variant for the input set was 24 which I dont understand. Can someone explain that also.

UPDATE:

I get how the answer is 14 in the given problem link - it seems to be just the shortest path between node 0 and 3. But with the 3 hour component how is the answer 24

UPDATE

I get how it is 24 - its a complete graph traversal at every hour and this is how I solve it

```<code>Hour 1
Node 0 to Node 1 - 10 people
Node 0 to Node 2- 5 people
TotalRescueCount=0
Node 1=10
Node 2= 5

Hour 2
Node 1 to Node 3 = 5(Rescued)
Node 2 to Node 4 = 5(Rescued)
Node 0 to Node 1 = 10
Node 0 to Node 2 = 5
Node 1 to Node 2 = 4
TotalRescueCount = 10
Node 1 = 10
Node 2= 5+4 = 9

Hour 3
Node 1 to Node 3 = 5(Rescued)
Node 2 to Node 4 = 5+4 = 9(Rescued)
TotalRescueCount = 9+5+10 = 24
</code>```

It hard enough for this case , for multiple evac and rescue points how in the world would I write a pgm for this ?

答:
This question is basically two-fold:

How do you solve the actual problem? and

How do you generally read in graph data?

The first question is a bit narrow, and it sounds like the second one is of more interest to you in the long run. So, let me just point  you to flow algorithms. It's a step up from Dijkstra in terms of implementation complexity, but as you already realized, there is just so much you can do with a single path. Network flows are a whole different thing.

As for reading your input, it dramatically depends on the kind of graph library you want to use. A few years ago, when I was active in these competitions, we weren't allowed to use 3rd-party libraries, so had to roll our own implementations.

In that case, you have to think ahead if you want to read in a complete matrix, or if you want to keep the graph as an adjacency list. These are the two most important data structures to know for graph algorithms. (more precisely, often you don't need to think ahead, because the problem input specification directs you to one or the other)

Reading input for an adjacency matrix is as straightforward as two nested for-loops. In the body of the inner loop, you simply read one value and assign it to one matrix cell. Done.

For adjacency lists you need to prepare the list of neighbors of a node for each of the nodes, i.e. for n nodes you prepare a list of size n that contains an empty list for each entry. Then you again have two nested for-loops: the outer loop goes over the nodes, the inner loop reads the neighbors of that node and adds them to the corresponding inner list. Voila - an adjacency list representation of the graph.

Important addition for programming challenges/competitions: Make sure that you know in your dreams how to write both variants before you even think about competing. There are limitless sample questions and practice sites out there. Search around for problems with graph input, then write and rewrite the input code again and again. It should almost always be nearly the same code, and once you've grown accustomed to it, reading in input like the one you gave above takes you 5 minutes at most. If you want to compete with the really strong players in that field, you should be able to code the input reading for this within about 1 minute or less.


答:
The most important thing is to clarify beforehand who has authority about which decisions. The biggest mistake you can probably make is to micromanage the project manager.

A reasonable agreement might be "I decide the overall budget and hiring, and leave resource allocation, planning and operational decisions to you, even where they affect my own developmentwork; if you're uncertain about any big decisions, ask me."

Title: Does it work when a developer is the project manager's boss?

Body:
I am in the planning stage of a project and I am looking to hire a project manager. I would like to do some coding and keep eye on all parts of the project. However, i have a feeling that a project manager will get better results. I have the following options:
1) manage the project and not code
2) hire a project manager and code myself

I am worried that the project manager will feel impeded by having the project owner in the development team. If I run the project, the team might fall apart causing the project to fail. To stick within budget, I have to be involved in one capacity or another.

Does anyone have experience with this situation, any suggestions?

more info: 4 in-house developers each responsible for a specific area. The developers can also outsource work if agreed to by the project manager.


问:
Why is HTML/Javascript minification beneficial
Why is HTML/Javascript minification beneficial when the HTTP protocol already supports gzip data compression?

I realize that Javascript/HTML minification has the potential to significantly reduce the size of Javascript/HTML files by removing unnecessary whitespace, and perhaps renaming variables to a few letters each, but doesn't the LZW algorithm do especially well when there are many repeated characters (e.g. lots of whitespace?)

I realize that some Javascript minification tools do more than just reduce size.  Google's closure compiler, for example, also tries to improve code performance by inlining functions and doing other analyses.  But the primary purpose of Javascript minification is usually to reduce file size.

I also realize there are other reasons you might want to minify aside from performace, such as code obfuscation.  But again, that reason is not usually emphasized as much as performance gain and file size reduction.  For example, Closure Compiler is not advertised as an obfuscation tool, but as a code size reducer and download-speed enhancer.

So, how much performance do you really gain from Javascript/HTML minification when you're already significantly reducing file size with gzip compression?

答:
Because gzip compression does have its own overhead (CPU). Minification is the first "low hanging" compression that can be applied without the CPU hit.

These may seem insignificant however, the numbers soon make sense when scale is involved.

Further, with minification you have less to gzip.


问:
How to devise instruction set of a stack based machine?
Stack based virtual machines like CLR and JVM has different set of instructions. Is there any theory behind devising the instruction set while creating a virtual machine? e.g. there are JVM instruction sets to load constants from 0-5 onto the stack

```<code>iconst_0
iconst_1
iconst_2
iconst_3
iconst_4
iconst_5
</code>```

whereas in CLR there are instruction set to load number from 0 to 8 onto the stack as follows

```<code>ldc.i4.0
ldc.i4.1
ldc.i4.2
ldc.i4.3
ldc.i4.4
ldc.i4.5
ldc.i4.6
ldc.i4.7
ldc.i4.8
</code>```

why there is no ldc.i4.9 and if ldc.i4  is there why we need the above opcodes? And there are others like these.

I am eager to know what is the reason behind this difference between opcodes of different VMs? Is there any specific theory to devise these opcodes or it is totally driven by the characteristics of the VM itself or depends on the high-level language constructs?

答:
The only book I know which consider issues in instruction set (ISA) design is Gerry Blaauw and Fred Brooks, most other books on CA just provide a classification and don't go very far.

For you problem at hand, you have to trade-off with the density of code. An ldc.i4 is enough to provide the functionality, but every case it is used, it would take says 1 byte of instruction and 4 bytes of constant. Providing a few special purpose ldc.i4.xx using only 1 byte of instruction help in increasing the density of the code. But obviously you can only have 256 one byte instructions, so you have to use them wisely.

And additional factor for VM (this factor is less true for hardware implementation) is that such special instruction will not only take less place in the instruction stream (with benefit on the cache pressure and thus on the speed), these instructions will be executed more rapidly than their equivalent.


问:
Paranoid Encryption
Call me paranoid, but I really like to keep my stuff secret, but readily available on the cloud. So, asking this question.

How safe and reliable is encryption software (e.g., truecrypt)? The reason I ask is that, what is I encrypt my data today with this software and after a couple of years, the software is gone ! What happens to my encrypted data?

Is it equally safe to AES encrypt using 7-zip? Will it provide the same level or equivalent level of encryption as truecrypt or other encryption software? (I agree truecrypt will be better because of the container encryption it gives.) And what happens if 7-zip shuts down after 5 years?

I am sorry if I am sounding paranoid, but I am coming back to my original question... Is there any application/software independent encryption? Meaning, can I encrypt with one software and decrypt with another so that I will not be dependent on just one vendor? I want my encryption to depend ONLY on the password and NOT on the encryption program/software?

The next question, can I write my own program that does AES/stronger encryption when I give it a passphrase, so that I don't need to depend on third party software for encryption? If yes, which language supports the same?

Can someone give me a heads up as to where to look for in case of writing my own encryption program?

答:
Can I still decrypt it in 10 years?

The file format for true-crypt containers is documented, and relatively simple. Writing a decryptor shouldn't be hard. The complex part is the file system, such as NTFS storing the files withing the container. But since there are open source drivers for NTFS, I wouldn't worry too much about that either.

So I wouldn't worry about the data becoming unreadable. Losing the ciphertext is much more likely than being unable to decrypt it.

How secure is it?

Concerning security, the strength of AES itself is probably sufficient, and if you're truly paranoid about progress of cryptoanalysis, you can use cipher chains.

There are some other issues:

An attacker who sees multiple revisions of the container can see which blocks were changed. This is typically the case if you host a container in the cloud. In particular this reveals hidden volumes.

The Key derivation function that turns the password into a key is rather weak. It uses only 1000 or 2000 iterations, making it quite fast to bruteforce i.e. the cost per password guess is pretty low. scrypt with well chosen parameters would make bruteforce harder by a factor of a million or so. This means you should choose a really high entropy password.

No integrity checks. An attacker can change arbitrary blocks of your container, changing the associated plaintext without TrueCrypt noticing.

While TrueCrypt has its flaws, it's very unlikely that a beginner will produce something more secure.

Title: Paranoid Encryption


问:
After how much line of code a function should be break down?
While working on existing code base, I usually come across procedures that contain Abusive use of IF and Switch statements. The procedures consist of overwhelming code, which I think require re-factoring badly. The situation gets worse when I identify that some of these are recursive as well.

But this is always a matter of debate as the code is working fine and no one wants to wake up the dragon. But, everyone accepts it is very expensive code to manage. I am wondering if are any recommendations to determine if a particular Method is a culprit and needs a revisit/rewrite , so that it can broken down or polymophized in an effective manner. Are there any Metrics (like no. of lines in procedure) that can be used to identify such segment of code. The checklist or advice to convince everyone, will be great!

答:
In my opinion, you cannot generalize how many lines of code a method or class should contain before breaking it up in smaller components. Instead of counting number of lines, you should count how many times a number of lines are reused. In example, if you have 3 lines of code you reuse again and again inside a method or class, then it is a good idea to extract this code into a method.

Another important aspect is your business domain. If you begin to break up your classes, just because you think there is to many lines of code, you will probably have to generate new classes and methods, with new names, that not necessarily fits the business domain. This kind of code is very hard to read and understand for other developers (and yourself after a few months).

If you feel that some code are unnecessarily complex, then you should consider rewriting it instead of breaking down the code. When analyzing and rewriting, you may find that it is a good idea to break some of the code down, but I don't think that should be the main objective. Over complex code will still be over complex, even if it is broken down.


答:
If you want to change this code, first write unit tests that validate it's functionality. Then as you make changes you will have confidence that you haven't broken anything.

There is no hard and fast rule about numbers of lines, but a function with 40+ lines is certainly a hint that it is too long. A function with 2 lines is not too small. Steve McConnell's Code Complete 2 refers to some studies and says that 200 lines is the upper limit for readability.

It's all about cohesion. A single function should do a single task, and all parts of the function should relate directly to performing that task.

Consider cyclomatic complexity. A high number of decision points and deep nesting may indicate too much code in one function.

Also, well-selected function and parameter names make code more readable because they act as a form of documentation. Everything that a function does should be immediately obvious from reading its name and its parameters. If it's hard to explain what a function does in a few comment lines, then you probably have too much code in one function.

Title: After how much line of code a function should be break down?

Body:
While working on existing code base, I usually come across procedures that contain Abusive use of IF and Switch statements. The procedures consist of overwhelming code, which I think require re-factoring badly. The situation gets worse when I identify that some of these are recursive as well.

But this is always a matter of debate as the code is working fine and no one wants to wake up the dragon. But, everyone accepts it is very expensive code to manage. I am wondering if are any recommendations to determine if a particular Method is a culprit and needs a revisit/rewrite , so that it can broken down or polymophized in an effective manner. Are there any Metrics (like no. of lines in procedure) that can be used to identify such segment of code. The checklist or advice to convince everyone, will be great!


答: Minification + gzip generally gives better results, because gzip is a general algorithm, not specifically adapted to one input or another, while minificator is aware about it's content and can do work that general compression algorithm can't. It can afford to be lossy as well (think: completely eliminate comments and whitespaces - that's 100% compression for this data, how you can beat that?), while general compression can't.</p>

Body:
Why is HTML/Javascript minification beneficial when the HTTP protocol already supports gzip data compression?

I realize that Javascript/HTML minification has the potential to significantly reduce the size of Javascript/HTML files by removing unnecessary whitespace, and perhaps renaming variables to a few letters each, but doesn't the LZW algorithm do especially well when there are many repeated characters (e.g. lots of whitespace?)

I realize that some Javascript minification tools do more than just reduce size.  Google's closure compiler, for example, also tries to improve code performance by inlining functions and doing other analyses.  But the primary purpose of Javascript minification is usually to reduce file size.

I also realize there are other reasons you might want to minify aside from performace, such as code obfuscation.  But again, that reason is not usually emphasized as much as performance gain and file size reduction.  For example, Closure Compiler is not advertised as an obfuscation tool, but as a code size reducer and download-speed enhancer.

So, how much performance do you really gain from Javascript/HTML minification when you're already significantly reducing file size with gzip compression?


问:
Copyrighting software, templates, etc. under real name or screen name?
My question is hopefully simple - should I copyright my work (art, software, web design, etc.) under my real name or my screen name? My real name and screen name are also easily connected with a bit of searching, so does it really matter in the end?

I'm not a professional (at this point).

I read this question and they recommended releasing on the app market under a company name.

I also read this question, but that didn't answer my question.

I know it probably matters for big projects, but for little projects, does it matter?

答:
I would recommend you copyright and licensing your code under your business name.

The question you are asking isn't about linking to your real name, it's about providing the legal niceties a business structure offers.  And yes, it matters for little projects as well as big projects.

Even though it was ridiculously easy to link through to what you claim is your real name, you should still consider using a business name.  I say "claim" because nobody knows if you're a dog or not.  Personally, I'm just a very sharp border collie.

All of the situations assume that you see continued success, and perhaps even astronomical success with selling your software.

When you bring other developers on board, it's easier to have them assign copyright to a business entity.  Likewise, if they are given joint ownership in the firm, assigning the assets (copyright and licensing claims) to a business entity allows things to be dividable.

How about when you decide to venture off to something else and want to sell off the assets you have delivered?  Instead of having to piecemeal everything, you can sell the business itself.  It's a much simpler transaction.

Think of yourself as building a brand right now.  If you decide to pursue other lines of business, you can generate another brand at that point.  Then you don't have to worry about consumer confusion created by having disjoint products under the same brand.

Once you incorporate your business (see additional details below), then you acquire legal protections and additional financial / tax options to consider that may benefit you.

There are the additional psycho-somatic nuances of a business name versus a single person, but the links you provided go into those details.

On the flip side, if things are an abysmal failure, you can abandon said business entity with less damage to your personal name and reputation.  You can't skip out on the taint completely, but it minimizes the damages and makes it easier to start over.  An example bad case scenario would be someone hacks your popular product and exploits it to push malware all over the place.  People will remember that product as the one that got hacked, and the associated business name might be irrevocably tarnished.

You don't have to incorporate right now to gain the benefits of a business name.  "Doing Business As" or "Assumed Business Name" is a time-honored construct for your situation.  You could very easily switch over to being the business "A Blue Scarab Production" by changing your website and the splash screens of your apps.  You can then hire a lawyer later on for incorporation considerations once you start growing in sales.


问:
When deciding on whether or not to work for a new company, what are your dealbreakers?
I know we've covered what questions you should ask about a company before you would decide to work there.  But what do you do with the answers?

In other words, what would you consider a dealbreaker?  I.e. what would scare you so much about a company that you wouldn't work there, even if everything else was great?

For example, if they tell me they don't use version control, I wouldn't work there.  End of story.

答:
Dealbreaker:

If they describe themselves as a "young company" and when you look around you don't see anyone over 35 in any kind of technical position.  There's clearly no long term technical career track, and probably nobody experienced enough to learn from.  Plus they're probably underpaying and expecting you to work 60+ hour weeks.

ContentLicense: CC BY-SA 2.5


问:
Are programmers bad testers?
I know this sounds a lot like other questions which have already being asked, but it is actually slightly different. It seems to be generally considered that programmers are not good at performing the role of testing an application. For example:

Joel on Software - Top Five (Wrong) Reasons You Don't Have Testers (emphasis mine)

Don't even think of trying to tell college CS graduates that they can
  come work for you, but "everyone has to do a stint in QA for a while
  before moving on to code". I've seen a lot of this. Programmers do not
  make good testers, and you'll lose a good programmer, who is a lot
  harder to replace.

And in this question, one of the most popular answers says (again, my emphasis):

Developers can be testers, but they shouldn't be testers. Developers
  tend to unintentionally/unconciously avoid to use the application in a
  way that might break it. That's because they wrote it and mostly test
  it in the way it should be used.

So the question is are programmers bad at testing? What evidence or arguments are there to support this conclusion? Are programmers only bad at testing their own code? Is there any evidence to suggest that programmers are actually good at testing?

What do I mean by "testing?" I do not mean unit testing or anything that is considered part of the methodology used by the software team to write software. I mean some kind of quality assurance method that is used after the code has been built and deployed to whatever that software team would call the "test environment."

答:
Programmers are definitely the right people to test some parts of the system -- in places they are the only ones who might be able to do it effectively.

One place programmers tend to be very bad at testing is the whole "use the UI like a normal user" bit -- they aren't normal users and don't behave like them. For example:

Programmers tend to be very good at getting text entries just right. A pretty common issue I see is leading or especially trailing spaces. Most folks don't seem them, but good programmers are probably religious about making their strings just the right string without extraneous spaces.

Programmers tend to be keyboardists, taking advantage of tabs and other shortcuts to speed up work. Normal users tend to grab the mouse between fields.

Programmers tend to understand what the system is telling them rather than ignoring error messages and just clicking OK.

So, normal users do lots of things programmers don't. You can't rely completely on the dev team for UAT.

Title: Are programmers bad testers?


答:
I don't think that there are a specific limit on number of lines that a procedure can contain. However, it should never be on a developer's mind.

There are a couple of things that one can apply to ensure scaling, manageability and readible to new developers.

Always try to do as much processing at the backend (database) side where possible
when it comes to logic. Let your stored procedures handle as much of the bulk of the
logic as possible to release the frontend code of unnecessary processing (IF,switch
statements) as it might have a performance cost when multiple threads are running to
take care of. This is of course if the logic make use of dataset from a database.

A method should always have a single responsibility. That means that if your method

calculates interest then it should not be responsible for emailing the user/client
the daily interest as well or a method where you add you items in a basket must not

handle the payments for you as well. It must have one purpose.

A method should always be open for extention and closed for modification. Modifying
the method changes it's purpose and complexity. Extending it keeps purpose and makes
it more powerful.

Rather have multiple classes seperating work than one class doing all the work. This
removes unnecessary complexity. This is called Interface segregation.

Point 2,3,4 are the S, O and I of the SOLID principals ensuring that code are scalable, managable and also readible when new developers join the team.

To verify your methods complexity run Visual Studios Code metrics (http://msdn.microsoft.com/en-us/library/bb385914.aspx). If the Maintainability Index of a class/method is smaller than 75% then it warns you of a method becoming to complex to handle. There are various other indicators using Code Metrics.


问:
Generate sequence of string of 4 characters
I'm facing problem with generating character sequence for SMS tracking. there should be a easy to enter code send with all the outgoing messages. Reply SMS will map with that code.
I can't generate next sequence of code from database because multiple clients may have read at ones and may end up with same code.

is there any workaround for this?

EDIT

Database is Informix.

答:
Do generate the codes, from a shared database. If the codes are shared between customers, the code database should be as well.

Any decent database can deal with concurrent access. I'd just generate codes at random, and try to insert them. If the insert fails, just generate another.

Note that there are only 456 976 alphabetic codes of length 4; if your 5K users generate 100 codes you're quickly out of codes. Adding numbers pushes it up to 1 679 616 alphanumeric codes, but gets you into 0/0 confusion.

See also my answer to a similar question on StackOverflow.


问:
Should programmers prefer making wide libraries or thin libraries?
For classes and functions, it is clear cut: each should do only one thing.

For libraries though, this is less clear. If you have a library with collections, it might have multiple collections. It might have useful functions like sorting, which aren't strictly collection based but users would expect. Each of these results in a 'wider' library.

On the other side is having a library for the specific collection type and/or with little built-in functionality. If you want a queue, it gives you a queue. If you want to sort that list, then the library lets you do that yourself.

What is the best practice here (if any)? I can see arguments for each side.

答:
Wide enough to make the main elements of the library usable.

Your example with sorting is a good one.  If your target language/environment has default sorting functions for collections and you, are implementing collections that cannot be sorted with the normal sort functions, then I would think it would be desirable to include sorting functions.

If you can implement the collections to sort with the default functions of your target environment then adding helper functions probably is not necessary and the library can be lighter.

Occasionally it is useful to add a convenience method even when the default functions do work if your library is a specific enough that there would be specific custom sorts that would always be needed like a job title seniority sort on an employee collection.


答:
Often instruction sets are devised by examining the code generated for similar machines to see which instructions occur most often.  The designers will also write compilers (or at least a back-end for GCC) using their proposed instructions to see how efficient (both in terms of code density and execution speed) the resulting code is.  I'm sure the designers of the CLR took a good hard look at the JVM to see how it could be improved, just as the designers of the JVM got insight from earlier VMs (p-system, Forth, Smalltalk).

General ISA design theory says that the most commonly-used opcodes should be the shortest, since this will lead to the best code density (and also the best performance, since shorter instructions tend to be simpler to decode).  Devising the actual encoding scheme (opcode+operand(s)+data type(s)+addressing mode(s)) is entirely up to the ISA architect and is one of those "black art" skills that involves lots of experience.

Title: How to devise instruction set of a stack based machine?

Body:
Stack based virtual machines like CLR and JVM has different set of instructions. Is there any theory behind devising the instruction set while creating a virtual machine? e.g. there are JVM instruction sets to load constants from 0-5 onto the stack

```<code>iconst_0
iconst_1
iconst_2
iconst_3
iconst_4
iconst_5
</code>```

whereas in CLR there are instruction set to load number from 0 to 8 onto the stack as follows

```<code>ldc.i4.0
ldc.i4.1
ldc.i4.2
ldc.i4.3
ldc.i4.4
ldc.i4.5
ldc.i4.6
ldc.i4.7
ldc.i4.8
</code>```

why there is no ldc.i4.9 and if ldc.i4  is there why we need the above opcodes? And there are others like these.

I am eager to know what is the reason behind this difference between opcodes of different VMs? Is there any specific theory to devise these opcodes or it is totally driven by the characteristics of the VM itself or depends on the high-level language constructs?


答: Use a transactional database, and make reading a code + incrementing the code to the next free one an atomic transaction. When you use a SQL database, google for "SELECT FOR UPDATE".

Title: Generate sequence of string of 4 characters

Body:
I'm facing problem with generating character sequence for SMS tracking. there should be a easy to enter code send with all the outgoing messages. Reply SMS will map with that code.
I can't generate next sequence of code from database because multiple clients may have read at ones and may end up with same code.

is there any workaround for this?

EDIT

Database is Informix.


问:
Best practice for writing a service
We currently have a C++ socket server used by a java client. All of the socket code in both C++ and java is stick-built at a low-level with messages passed via JSON strings.

Are there cots packages or better techniques commonly used in this situation to reduce the cost of future development and maintenance?

答:
Seems your only issue is the client communication protocol - which I assume is a custom thing. This isn't necessarily a problem. RPC mechanisms like Google's Protocol Buffers requires you to define your packet contents anyway, but there are loads of existing communications systems  that might help you.

Web services are good for interop, as they're mostly standard (just be aware that WCF ones do not work fully with Java or PHP web services), but they're relatively slow. Thrift is a souped up RPC, or ZeroMQ is a good messaging system. Any of these might help take the comms factor out of your problem.

Title: Best practice for writing a service


问:
How is the development of languages like Python and Perl funded?
The title pretty much gives you the gist of the question, but allow me elaborate a bit nevertheless. Apart from Google's involvement on Python, and Activestate's on Perl development (Strawberry AFAIK doesn't make any money on its own product) I'm interested in what are the major sources of funding of such.

Are there any texts that cover this? I tried searching, but found nothing apart from the "history of" and "it's opensource, everyone gives in" ...

答:
Assuming that by "languages like" you mean open-source languages, the answer in general is that they are funded by the people that contribute their own time to it, and by the organisations that contribute their members' time to it.

Using Python as an example, Google uses Python extensively, and regularly contributes back to the project (not just Guido's work, but many other employees as well).  I believe they're also happy for employees to spend some time contributing in non-coding ways (e.g. taking part in python-dev discussion).  There are many other companies for which this is also true, to a greater or lesser extent.

Python also has the Python Software Foundation (PSF), which is funded for the most part by sponsors (typically large companies like ActiveState, Google and O'Reilly - the web page has a current list).  Although the PSF isn't responsible for the day-to-day work on Python, it does advance the language in various ways, particularly related to funding - for example funding conferences (where often a lot of development is done), occasionally funding work on a specific project, working with "Summer of Code" students, and so forth.

Throughout much of the life of Python, one or more core developers have been employed to specifically work on development of Python itself (either part time or full).  For example, Guido developed Python while at CWI, CNRI, BeOpen.com, and most recently at Google.

Other implementations of Python (work on which feeds back into the core Python and CPython) are funded in similar ways.  For example, until very recently Microsoft funded (completely) the development of IronPython, and the European Union funded (partially but significantly) the development of PyPy.


答:
IMHO you should break up your code, so it only does one thing (not counting the argument checks). In general, If statements should be viewed as opportunities to extract functionality :-) In effect, the if method makes the code do two things.

Now, when to do it is another question. Do it quietly whenever you have the slightest interaction with it -- i.e. implementing new functionality or bugfixing. If someone asks, you did it to make sure, that your new code works properly -- and that would not even be lying


答: You may not get too much performance benefit but you will still reduce your bandwidth usage. If you can shave a few kb off your js (and css) files through minification (and use of css sprites to reduce number of requests) and you are serving 1000's of users a day, after a month you will significantly reduce your bandwidth.</p>

Title: Why is HTML/Javascript minification beneficial


答:
The single most expensive thing you do in a web application is send things down the wire. Sending less stuff down the wire is almost always a net win if you are paying in CPU cycles.

In addition, I don't have anything scientific to back this, but I'd expect that minification tools can probably compress javascript better than gzip if for no other reason than minification tools are domain specific and can be tuned to better compress javascript whereas gzip is a generic tool and will compromise into the middle.


答:
I prefer to give my functions "speaking names", so I can save on commenting stuff.   This leads to many small functions, which do specific operations.

So I extract a function from code, if...

...I use the code at more places.

...the name of a function would get rather long and implying many operations of different concerns.

With this approach I never end up with a function of more than 50 lines and readable code.


问:
At what point can I say I've "learned" a language?
In my few years of programming, I've toyed with everything from Ruby to C++.  I've done everything from just learning basic syntax (Ruby) to completing several major (for me) projects that stretched my abilities with the language.  Given this variety (and the fact that truly learning a language never stops), when can I say I know (or have learned) a language?</p>

答:
This is more of a opinion based factor. In all technical terms "Learned" would mean having a complete knowledge of, as in you would be expected to know EVERYTHING of the language. </p>

<p>However in the world of programming I believe it's more about if you can program fluently in the language to complete a objective/task. It also probably means if you're comfortable with the language. Sure you could go out there and get a degree after years and years of college, but that's only to get noticed? You define when you can say you've learned a language. </p>

Body:
This is more of a opinion based factor. In all technical terms "Learned" would mean having a complete knowledge of, as in you would be expected to know EVERYTHING of the language.

However in the world of programming I believe it's more about if you can program fluently in the language to complete a objective/task. It also probably means if you're comfortable with the language. Sure you could go out there and get a degree after years and years of college, but that's only to get noticed? You define when you can say you've learned a language.


答:
It is strange that no one mentioned this before:
Adding such a functionality to the bug tracker would motivate employees to try to game the system.

This is a common problem for approaches like what the question presented, among other similar ideas (paying by number of code lines, paying by number of bugs). This will encourage many to focus on getting a good score, instead of solving problems related to the software they are working on.

For example, trying to submit a bug report with a wording to lessen one's own blame, and shove it on someone else can lead to developers misunderstanding the cause of the problem (or the work being given to another developer who does not know that section of a code as good as the one who was working on it the most and who was the primary cause of the bug) leading to more time and effort to fix the problem.


问:
String class based on graphemes?
I'm wondering why we don't have some string classes that represent a string of Unicode grapheme clusters instead of code points or characters.  It seems to me that in most applications it would be easier for programmers to access components of a grapheme when necessary than to have to organize them from code points, which appears necessary even if only to avoid casually breaking a string in "mid-grapheme" (at least in theory).  Internally a string class might use a variable length encoding such as UTF-8, UTF-16, or in this context even UTF-32 is variable length; or implement subclasses for all of them (and optionally configure the choice at run-time so that different languages could use their optimal encodings).  But if programmers could "see" grapheme units when inspecting a string, wouldn't string handling code in general be closer to achieving correctness, and without much extra complexity?</p>

答:
Seems like the best way to get correctness is to keep programmers from doing "string hacking" ... it just isn't OK to write your own word wrap, hyphenation, word count, justification, cursor movement, etc. routines. All the modern UI frameworks will do this stuff for you these days.

That is, the abstraction you'd usually work with is more of a "paragraph display object," such as for GTK:
http://library.gnome.org/devel/pango/stable/pango-Layout-Objects.html

rather than a grapheme string, such as:
http://library.gnome.org/devel/pango/stable/pango-Glyph-Storage.html

To get to a string of glyphs you need info that's only available at the "view" level, so most uses of strings might not have this info. For example, you have to know the font, because fonts can have different ligatures.

Aside from that kind of practical matter, glyphs probably aren't what you want.

In many contexts, you want to use the proper Unicode attributes, shown in this API for example:
http://library.gnome.org/devel/pango/stable/pango-Text-Processing.html#PangoLogAttr

As you can see from that struct (which reflects the Unicode algorithms) doing various things at glyph boundaries is not any more correct than doing them at character boundaries.

These two specs describe the algorithms to find different kinds of boundaries:

http://www.unicode.org/reports/tr14/

http://www.unicode.org/reports/tr29/

Doing text processing involves finding those boundaries with the algorithms and then working with the boundaries.

If you start digging in on just how hard it is to handle all languages correctly, you'll very quickly realize you need a library that looks at whole paragraphs and handles them properly. Windows, Mac, Linux (Qt and GTK), and Java all come with facilities for this, plus there's http://site.icu-project.org/ for example.

When writing web apps, unfortunately you pretty much have to let the browser (probably helped by the OS) do this stuff, as far as I know. All you can do in JavaScript or on the server side is mess it up.

Maybe I'd sum up the answer as: most string manipulation on natural language text is broken, so not much point worrying about the string class, other than maybe to have one with no methods on it ;-)

Title: String class based on graphemes?


答:
You can rarely say you've learned a language. That implies you're done learning about it, which is... foolish.

Saying you know a language is fine when you can write code that isn't blatantly breaking idioms in the language (maybe after a week of de-rusting the knowledge) without referring to a syntax reference.

Title: At what point can I say I've "learned" a language?

Body: In my few years of programming, I've toyed with everything from Ruby to C++.  I've done everything from just learning basic syntax (Ruby) to completing several major (for me) projects that stretched my abilities with the language.  Given this variety (and the fact that truly learning a language never stops), when can I say I know (or have learned) a language?</p>


答:
At what point can you say that you've "learned" a language like English or French? I think most people would accept that you've learned a language when you can use it to communicate. You don't have to know every word or understand every idiom, but you should know most of the (rather small) subset of the language that people use in daily conversation. Having "learned" a language to that extent, you can continue to learn more as you use the language daily and expose yourself to more and more of it. By the time you die, you still won't know all there is to know about the language, but nobody will say that you never "learned" the language.

So it is, I think, with computer languages. You can say that you "know" a language like C++ or Ruby when you can write useful programs in it. If you need to quantify the degree to which you know the language, use the same terms that you'd use for a human language. Say "I know a little C++" or "I know conversational C++" or "I'm fluent in C++" to mean that you know just enough to scrape by, enough to get useful things done, or that you're an expert, respectively.


答:
It will wind up punishing his most prolific programmer. Odds are, one or two people might be the best employees who have worked on the most projects. If you have, in a 10-person department, one coder who is just a fountain of output and he's written 60% of the interface code, then 60% of the bugs will be in his code.

Explain that this system would make it look like the person who writes the most code is the worst programmer, and the person who writes the least code is the best programmer.


问:
Measure of power other than Turing completeness
I originally tried asking this on StackOverflow, but it was too subjective :-(. I am interested in methods of defining the power of programming languages. Turing completeness is one, but it is almost universally satisfied. What would be nice is to define a measure of power that discriminates among programming languages that are actually in used. For example, can anyone propose a non-subjective method that would discriminate between assembly and Java?

Turing completeness means that a language is maximally powerful in what it can output (which pretty much means it can do anything non-time based in the real world). So if we want to define a stronger measure of power, we need to take another approach. Shortness was suggested in the original question, but this is not easy to define at all. Does anyone have any other suggestions?

答:
The notion you are looking for is called expressiveness and Matthias Felleisen has a mathematically rigorous definition:

"On the Expressive Power of Programming Languages"

www.ccs.neu.edu/scheme/pubs/scp91-felleisen.ps.gz (Postscript version)

The intuition behind the idea is that if you have two equivalent programs in two different languages-- say, program A in language X and program B in language Y-- and if you make a local change to A that requires a global change to B, then X is more expressive than Y.

One example Felleisen provides is assignment: In the Scheme programming languages you can remove the assignment operator and still have a Turing complete language. However, in such a restricted language, adding in a feature that would be localized if assignment was allowed would require a global change to the program without assignment.

My discussion has simplified some details, and you should read the paper itself for the full account.

To answer your other question: You can say that Java is more expressive than assembly because you can add a new class to your Java program, and then gain the benefits of polymorphism by having other parts of your program call its methods without global modification. Exception handling is another example where Java is more expressive than assembly: You simply need to write a single throw statement to transfer control up the stack. On a more elementary level, you can also add a new case statement near the beginning of a switch and you won't have to worry about recalculating any jump offsets by hand.


答:
People don't go to work intent on making mistakes, and any strategy set in place, to specifically attach blame for what may or may not have been human error is ridiculous - not to mention extremely unprofessional.

At the very least, a "responsible party" assigned to take charge and "fix" the issue, or come up with a plan to track and/or prevent similar events from occurring, would be good. Sometimes the solution is nothing more than additional training. I've worked for a number of companies where it was part of your job description, to get a "company paid/company time" education. One place even built an entire "training center", that the local college "borrows" on occasion, for their industrial technologies courses.

I have worked in a manufacturing environment for the last 20 years, where programming mistakes don't just cause errors, they physically destroy things, and/or worse, they get people hurt. However, one constant in every field of manufacturing that stands strong, is that there is never, under any circumstances, someone to blame. Because it's a defect in the system, plain and simple - not a defect in the people. Look at it this way - the use of spell checker - a highly effective tool, for those less fortunate in the area of textual virtuosity, or maybe just those a little over worked... but by no means a method of blame or accountability.

A work environment, no matter what kind, or for what purpose it serves, is a system. A system made up of individual components, that if properly "in tune", works in total harmony - or some semblance of such.

Suggested reading on your boss' part: The 7 Habits of Highly Effective People

It sounds like he could use a little humility, if not a reality check. He's just as much a part of the team, as everyone else, and he needs to realize that - or it just won't work, and in the end, he will be holding the bag regardless.

Suggested reading and/or research on your part:

Look into 5 why analysis, root cause analysis... anything thing that puts you in a better position to offer a solution, not a problem. And your disagreement with your boss, is just that, a problem, not a solution. Offer him something better, something that makes sense, and even be prepared to allow him to take credit for the idea.

Right now it doesn't seem like he is prepared to fix anything, because he does not have a firm understanding of what is broken, if there is anything broken at all - other than his "I'm the boss" mentality.

Good Luck! I hope you manage to get through this, in a manner that's acceptable for all, especially in these times.

EDIT: Personally, from my own experience... "Go ahead, blame me. Because sure enough, I'll fix it, and down the road, when it happens again, who will be there to save the day? yep, you guessed it... me, with a big ole grin."


答:
My personal answer for this is when,

I know the basics to write a simple production-level program.

I've spent at least 3 straight hours solving a problem that seemed simple but
 wasn't.

From there on, I wouldn't call it learning, but mastery.


答:
I think people are focusing on the finality of the word "learned" being perfect tense it means you're finished learning. And as everyone noted, programming languages are living entities just like spoken languages. For example someone who had complete mastery of C# 2 would look at C# 3 with LINQ, Lambdas, var keyword, object/collection initializers, and extension methods and find that a lot has changed from what he learned for the previous version. The same is happening with C# 4 with await, async keywords and other new language constructs.

And we're just talking syntax here. We forget that most languages are paired with a framework. C# has the .NET framework, Java has it's own framework, as does Ruby, C++, PHP, and PERL. Think of the framework for a language as the vocabulary and the language itself is just syntax. Knowing the language means you know how to make a sentence in the language. Knowing the framework means you can express yourself well in the language. Finally, once you know the syntax and vocabulary, you need to learn the idioms so that you write code as a "native speaker".

I'd say there are several levels of learning.

Hello World (you can write the most rudimentary programs.)

Proficient (you can write basic programs but need to consult online help regularly)

Fluent (you can write advance programs with some reference needed).

Native speaker (you can write advanced programs with minimal online help, your code is indistinguishable from another native speaker's code).


答:
I have a simple guideline which I read somewhere maybe ten years ago. I like it when a method definition fits my screen, I don't like scrolling to read.

I do believe striving for shorter methods is good, makes you question whether you can achieve the same functionality in less code - thus less bugs. Also, in my experience when a method is too long, it is probably doing too much.


答:
I once had a boss implement a system very similar to this, and although it wasn't programming (it was print design for a daily newspaper) the concept and appropriate response are the same.

What she did was instead of adding a 'person to blame' field on our paperwork she gave each of the designers a set of colored stickers. Each designer got a different colored sticker and was instructed that for any design worked on or even touched the sticker must be added to that design's paperwork.

The boss' stated goal for "the sticker initiative" was to establish the source of all our department's errors (mistakes in paperwork, misfilings, bad copy, essentially the print equivalent of bugs)

What we did was gave each of the other designers a quarter of our stickers so that we each had all the colors, and instead of putting just our color on each design we put all four of the designers' colors.

Don't just write your name in the [Blame] box- put everyone's name that is on the team/project, and make sure the whole team does the same.

We worked together against her orwellian bitchiness and as a result we actually ended up catching each others mistakes and talking to each other about it and ultimately had a significant reduction in errors. She was a sh*t manager though, and instead of recognizing that her initiative ended up uniting us and increasing productivity she got all butthurt and disbanded the sticker system and declared it a failure and formally reprimanded all of us.


答:
It depends on who is asking

The person who asks propably has a certain idea what level of skill is expected from someone who says that he has "learned a language."

Basically, i encountered two archetypical scales, by which people judge the answer to the question "have you learned X?"

For most nerds it is a trick question to weed out posers
This is already demonstrated by the other answers to your question ;).
If you say you learned it you fail in seeing the scope of the task, which is implicitly "perfection", and, much worse: you fail in humility.

For most bosses, you "have learned it", if you can solve their problems, a criterion oftentimes already met if your code compiles. Answering his question in a humble way will lead to him assigning the task to a poser who may also be a relative.

So, what's your audience?


问:
Why is it that MS Data Access story is so fractured ? Is it the nature of Data Access or is just MS?
This StackOverflow question asks "where can I get Microsoft.Data.Objects"

It turns out the answer was probably that its in the CTP4 (code first) release of Entity Framework 4
However there where a lot of guesses.  Including

System.Data

Entity Framework

Microsoft.ApplicationBlocks.Data

Microsoft.Practices.EnterpriseLibrary.Data

10 years ago if someone asked a similar question for they might have gotten DAO, RDO, ADO.

Is this just the nature of the beast or is it MS.

Does this pattern happen with other vendors? Where the base data access strategy is either wrapped or changed?

答: Personally I think it is more of a result of the influence of marketing within Microsoft. By all rights, most of these technologies could easily be just released as version upgrades of the older versions, but there seems to be a big need to put on this image of continually reinventing even something as basic as a data access layer.</p>


答:
It's a very easy rule: Functions should be short. As in, 5-7 lines.

It's almost always worthwhile to refactor very large functions, but you do need unit tests first.

Note: It's much easier to refactor large functions before they become part of the accepted codebase, and the way to do that is code review. I.e. when someone else codes up some monstrosity, you BLOCK the commit at the code review and make them fix it.


问:
How should I structure a solution for a long term project?
I'm about to create a do-everything dashboard for my team and am still having second thoughts about my project/solution structure.  Since this could be a long ongoing project, I want to get the structure right from the beginning.

This is what I had in mind:

Create a  solution named "doEverythingDashboard"

Delete the project named "doEverythingDashboard" under the solution "doEverythingDashboard"

Create winform project named "interface"

Create console applications projects for each functionality of "doEverythingDashboard"

Reference each console application in "interface"

Does this make any sense?  Would it make more sense to just have one project and create a class per functionality instead of an entire project?

答:
As mentioned above, just start writing code. BUT, if you go down the TDD route, future refactoring will be a lot easier.

There are some things to keep in mind though. Try to keep logical parts of your solution separate, eg, don't put business/domain logic in presentation layers (web/windows forms) and don't access the database/repository directly from the presentation layer/UI. Depending how complex your solution is you could use the traditional 'data access layer', 'domain entity/business logic layer', 'presentation layer' and have a project in your solution for each of these.

Some background reading that may help... http://xprogramming.com/classics/expemergentdesign/


问:
Reasonable Number of Directed Graph Nodes and Edges
How many directed graph nodes are typically represented in the browser? I'm working with some large data-sets with nodes and edges more then 400,000. I'm wondering if I am going down a fruitless path trying to represent them in the browser via arbor.js or similar JS libraries. What's the most effective way to allow a large number(large relative to my domain of real estate transactions, maybe 1-10,000) of users to visualize and browse a large directed graph of up to 500,000 records?</p>

答:
Limiting what is shown on screen is a necessity with that large of a graph, not only for performance reasons, but you would cause information overload for users. depending on how this information is used there are a few different way to determine what to display.

If you need to show how to get from A to B.

Show only nodes and edges on the "best" path(s) however best is determined.

If users need to navigate from node to node.

show only current node and connected nodes.

Optionally only show incoming/outgoing connections


问:
How do you deploy your ASP.Net MVC3 application to the production server?
I just want to find out the best practice to deploy your MVC3 application and what tool you use to get the job done.

I am using Visual Studio 2010.  I publish my web site, then manually backup whats on the production server, then upload the new one there. It's tedious and error prone.

What should I do to make this job easier?

答: You may want to try TeamCity or any other Continous Integration Tool. We use TC and it's really painless the deployment process since it takes whatever you have on your Source Control Server (SVN in our case). TC isn't free but I think there are some other tools that do are</p>


答: Visual Studio has nice publishing tools that will take care of the web.config transforms for you while publishing. I found it to be quite effective as long as you have access to the web server from your desktop.</p>

Title: How do you deploy your ASP.Net MVC3 application to the production server?

Body:
I just want to find out the best practice to deploy your MVC3 application and what tool you use to get the job done.

I am using Visual Studio 2010.  I publish my web site, then manually backup whats on the production server, then upload the new one there. It's tedious and error prone.

What should I do to make this job easier?


问:
My boss decided to add a "person to blame" field to every bug report. How can I convince him that it's a bad idea?
In one of the latest "WTF" moves, my boss decided that adding a "Person To Blame" field to our bug tracking template will increase accountability (although we already have a way of tying bugs to features/stories). My arguments that this will decrease morale, increase finger-pointing and would not account for missing/misunderstood features reported as bug have gone unheard.

What are some other strong arguments against this practice that I can use? Is there any writing on this topic that I can share with the team and the boss?

答:
To give the boss some credit, the concept of "blame assignment" is already baked into tools like SVN, and appropriate use of the data can be constructive to developers in "finding out who to talk to" while debugging, e.g.: http://www.codinghorror.com/blog/2007/11/who-wrote-this-crap.html

While I agree with gnat's response above that a Root Cause field is a good thing, this isn't the same information, and "denormalizing" the field to sometimes assign the previous developer name(s) for the affected source, and sometimes have a technical description (e.g. "didn't scale to 10000 users") will just muddy the waters.  I'd advocate for keeping a Root Cause field clearly a technical description (e.g. even when a clear programmer error, have it capture details such as "IndexOutOfRange Exception when fooData=999")  This can potentially provide some useful feedback when reviewed en masse, and allow for some corrective actions to be taken to resolve entire classes of issues with architectural or framework changes (e.g. improving custom container classes, top-level exception handing)

That said, adding a Person To Blame field clearly can send a very bad message and destructive message to a software team that management wants to single out and punish individual developers who break code most often.  I suspect manager believes that this public scrutiny will cause developers to be more careful and self-regulating to avoid getting their names on this "wall of shame", and doesn't understand why developers would feel threatened by this, especially if it is added generically to every bug report.

The problems with adding this as a bug field/potential metric are easy to start enumerating:

Bugs are highly variable in difficulty to resolve, and a simple statistic of bug count/developer will not reflect this.

Developers are highly variable in capability " " " " " " " " " " "

Many software systems have components that need refactoring, however refactoring legacy components (particularly if the legacy base has no/limited unit testing facilities) will initially introduce bugs.  Developers are likely to be discouraged from this "good" activity, if there's a stigma/fear associated with generating new bugs (even if these are trivial to resolve and the end result a major improvement in the system.)

Testers may file a highly variable number of bugs related to the same issue, resulting in highly skewed bug counts/developer, unless a more detailed analysis is done.

That's just the tip of the iceberg.  Combine these with the finger-pointing of who expected what API behavior, incorrect expected results in tests, and "earlier in the chain" issues with incorrect/missing requirements, and it should be obvious that a metric like this is doomed as valueless (unless the goal is to damage morale and cause a mass exodus.)

Back to the boss viewpoint, it's OK that he/she wants to find out if there are developers who are breaking code repeatedly, and to try and do something (hopefully constructive) about that.  Trying to get this information by adding a field to bug reports is not going to provide meaningful information for the reasons listed above.  In my experience, this information can be learned by being plugged in with the team, participating in most of the team meetings, integrating (carefully) information learned in occasional one-on-one meetings with team members, and getting familiar with the subsystems in the code (even if they can't read code.)


答:
I pretty much always use VS publish to a local directory and upload via FTP, if I'm using embedded databases I don't transfer over App_Data.

I guess it isn't the best way, but I've found it to work quite well. I also use SVN for version control so I don't really need to back up much on the production server.


问:
Use constructor or setter method?
I am working on a UI code where I have an Action class, something like this -

```<code>public class MyAction extends Action {
    public MyAction() {
        setText("My Action Text");
        setToolTip("My Action Tool tip");
        setImage("Some Image");
    }
}
</code>```

When this Action class was created, it was pretty much assumed that the Action class won't be customizable (in a sense - its text, tooltip or image will be not be changed anywhere in the code). Now, we are in need of changing the action text at some location in code. So, I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

```<code>public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip");
        setImage("My Image");
    }
}
</code>```

He, however, thinks that since setText() method belongs to base class it can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

```<code>MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the existing text.
</code>```

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action? The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

答:
Think of how instances will be used and use a solution that will guide, or even force, the users to use those instances in the right, or at least best, manner.  A programmer using this class will have a lot of other things to worry and think about.  This class should not add to the list.

For instance, if the MyAction class is supposed to be immutable after construction (and possibly other initialization), it should not have a setter method.  If most of the time it will use the default "My Action Text", there should be a parameterless constructor, plus a constructor that allows an optional text.  Now the user doesn't need to think to use the class correctly 90% of the time.  If the user usually ought to give some thought to the text, skip the parameterless constructor.  Now the user is forced to think when necessary and can't overlook a necessary step.

If a MyAction instance needs to be mutable after full construction then you need a setter for the text.  It's tempting to skip setting the value in the constructor (DRY principle--"Don't Repeat Yourself") and, if the default value is usually good enough I would.  But if it's not, requiring the text in the constructor forces the user to think when they should.

Note that these users are not dumb.  They just have too many real problems to worry about.  By thinking about your class's "interface", you can keep it from becoming a real problem also--and an unnecessary one.

Title: Use constructor or setter method?


答:
I think your manager is trying to solve a problem with the wrong solution. I think maybe there is an issue that too many bugs are being released and your manager wants the developers to take more ownership and accountability towards the code that they write.

Using test driven development and setting up a continuous integration server (like Jenkins) will help to solve this problem, without introducing the "blame game". A continuous integration server is important to this because when someone commits code that "breaks the build" an email goes out to the team showing the person to blame. Since this code hasn't been released to a production environment, this type of blame is more proactive and encouraging (and fun!).

The result is that developers will take more ownership, feel more confident, and there will be less bugs in production code.


问:
Pronunciation in programming?
How do you correctly or erroneously pronounce programming terms?  Any that you find need strict correction or history into the early CS culture?

Programming

char = "tchar" not care?

! = bang not exclamation?

# = pound not hash? Exception #! = shebang

* = splat not star?

regex = "rej ex" not "regg ex"?

sql = "s q l" not "sequel" (already answered, just i.e.)

Unixen

| = pipe not vertical bar?

bin = bin as in pin , not as in binary?

lib = lib as in library , not as in liberate?

etc = "ett see" , not "e t c" (as in /etc and not "&c")

Annoyance

/ = slash not backslash

LaTeX = "laytek" not "lay teks"

答: GUI: gee-you-eye vs. "gooey". I always assumed it was the former, but I've heard several people (with far more professional credentials than mine, that being "barely amateur") refer to it the other way.</p>

Title: Pronunciation in programming?


问:
How does having assets saved on a secondary domain(s) reduce the load time of the website?
I went for an interview yesterday where I was asked this question:

"How does having assets (images/videos) stored on a secondary domain (assets.example.com) reduce the load time of example.com?"

To that I answered that by having the code "call" those assets from a secondary website it reduces the traffic that is coming to the main domain and therefore only applying bandwidth to the main domain vs having to also serve bandwidth to request assets.

Is that correct?

Also, If i am correct, would you say it makes sense to start new websites with this in mind or do you prefer having it done after large traffic rates are achieved?

答:
I'm sorry, but your answer is incorrect. The main reason to use a sub domain would be to maximize parallel downloads, and you could take it a step further if said sub domain was cookie free. From Yahoo's Best Practices for Speeding Up Your Web Site:

Split Components Across Domains

Splitting components allows you to maximize parallel downloads. Make sure you're using not more than 2-4 domains because of the DNS lookup penalty. For example, you can host your HTML and dynamic content on www.example.org and split static components between static1.example.org and static2.example.org

and:

Use Cookie-free Domains for Components

When the browser makes a request for a static image and sends cookies together with the request, the server doesn't have any use for those cookies. So they only create network traffic for no good reason. You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there.

If your domain is www.example.org, you can host your static components on static.example.org. However, if you've already set cookies on the top-level domain example.org as opposed to www.example.org, then all the requests to static.example.org will include those cookies. In this case, you can buy a whole new domain, host your static components there, and keep this domain cookie-free. Yahoo! uses yimg.com, YouTube uses ytimg.com, Amazon uses images-amazon.com and so on.


问:
2D Image Creator for a video game
I need to make a few images for an arcade video game I'm making in Java. As of right now, I have drawings that animate, but there are two problems.

The drawings are horrible, and as a result, the game won't get enough attention.

It's a pain to have to change each coordinate for the drawing, as the drawings are fairly complex.

I'd like to use images. I feel they could solve my problem. They would look better than the drawings, and it would only have an x and a y coordinate, rather than the many coordinates I need for each drawing. So, in a sense, I have two questions.

Would images actually help? Would they solve my 2 problems? I just want to clarify.

How would I make these images. I don't think I can copy them off of the internet because I plan on publishing this game. So, is there any software where you can make your own images? (It has to be in an image type that Java can support. I'm working with java).

It also, as stated by the header, needs to be a 2D image; not 3D

答:
For creating images, have you considered MS Paint?

For displaying images, have you considered loading them as textures?

There's nothing else to say really, without knowing what frameworks you're using.

Title: 2D Image Creator for a video game


答:
Add a fluent 'setText' method:

```<code>public class MyAction ... {
  ...
  public MyAction setText(String text) { ... ; return this; }
}

MyAction a = new MyAction().setText("xxx");
</code>```

What could be clearer than that?  If you decide to add another customizable property, no problem.

Title: Use constructor or setter method?

Body:
I am working on a UI code where I have an Action class, something like this -

```<code>public class MyAction extends Action {
    public MyAction() {
        setText("My Action Text");
        setToolTip("My Action Tool tip");
        setImage("Some Image");
    }
}
</code>```

When this Action class was created, it was pretty much assumed that the Action class won't be customizable (in a sense - its text, tooltip or image will be not be changed anywhere in the code). Now, we are in need of changing the action text at some location in code. So, I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

```<code>public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip");
        setImage("My Image");
    }
}
</code>```

He, however, thinks that since setText() method belongs to base class it can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

```<code>MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the existing text.
</code>```

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action? The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

Body:
Add a fluent 'setText' method:

public class MyAction ... {
  ...
  public MyAction setText(String text) { ... ; return this; }
}

MyAction a = new MyAction().setText("xxx");

What could be clearer than that?  If you decide to add another customizable property, no problem.


问:
How to model the components of a non Information System?
I am working on a kernel-related project (specifically related to the TCP/IP stack of the kernel).

I need to build some models to describe the functionality and components of my system.
Initially I thought about using a Class Diagram, as it can describe the general architecture of my system. But it doesn't make sense since my code is VERY structured (written in standard C).

I also thought about DFDs: they'd describe the processes of my system, and how the data is flowing. But they contain something which doesn't really fit in: data-storages.
I have no databases here (at all).

For the functionality, other team members suggested using Activity and Sequence diagrams, which is kinda okay with me, but what about the system components?

So basically my question is: If I want to describe the components of my system, what do you suggest as a meaningful diagram ?

Again, the project is a research low-level systems-oriented project with almost no user-interface at all.

答:
All the documents you described will work to describe your system from the perspectives they capture.

A class diagram is to show the structure of your project without needing to see the code, the fact your code is very structured is irrelevant.

A DFD does not need to have a data storage listed, not all systems store data, but its still important to map how data flows through the system even if the data leaves the system as an end condition.


答:
I think the technique you are looking for is called "sprite animation".

The idea is you have pre-rendered images of the object you want to animate and your program very quickly changes which image of the set is displayed. Think about a film strip of a person walking - each cell has them in a slightly different pose. When you project these images onto a screen, and then run the film through the projector very fast it makes it look like there is a person walking on the screen.

It sounds like what you were doing up to now was animated vector graphics - your images wasn't stored as bitmaps, it was coordinates for geometric shapes. I think this is how some Flash games work, though I'm not certain how much is vector graphics and how much is raster (bitmap) graphics.

As far as how to create the images, well you will need some art skills. You can hand-draw every possible animation pose and then scan them into your computer. You could draw them directly to your computer with a drawing tablet. You could draw them in Photoshop, Illustrator, or even MS Paint (I've seen some very cool sprites created in Paint). You could build a 3D model and then render different poses/positions to different images.

Title: 2D Image Creator for a video game

Body:
I need to make a few images for an arcade video game I'm making in Java. As of right now, I have drawings that animate, but there are two problems.

The drawings are horrible, and as a result, the game won't get enough attention.

It's a pain to have to change each coordinate for the drawing, as the drawings are fairly complex.

I'd like to use images. I feel they could solve my problem. They would look better than the drawings, and it would only have an x and a y coordinate, rather than the many coordinates I need for each drawing. So, in a sense, I have two questions.

Would images actually help? Would they solve my 2 problems? I just want to clarify.

How would I make these images. I don't think I can copy them off of the internet because I plan on publishing this game. So, is there any software where you can make your own images? (It has to be in an image type that Java can support. I'm working with java).

It also, as stated by the header, needs to be a 2D image; not 3D


问:
Why is it good to split a program into multiple classes?
I'm still a student in high school (entering 10th grade), and I have yet to take an actual computer course in school. Everything I've done so far is through books. Those books have taught me concepts such as inheritance, but how does splitting a program into multiple classes help? The books never told me.

I'm asking this mainly because of a recent project. It's an arcade video game, sort of like a Flash game as some people have said (although I have no idea what a Flash game is). The thing is, it's only one class. It works perfectly fine (a little occasional lag however) with just one class. So, I'm just asking how splitting it into multiple classes would help it.

This project was in Java and I am the only person working on it, for the record.

答:
First of all, note that I'm a C++ and Python, not Java, so some of this may not apply quite as fully.  Please correct me if I make some incorrect assumptions about how classes work in Java.

Classes are primarily useful when they are instantiated.  A class of which no instances are created really is really just a glorified namespace.  If you use all your classes this way, then indeed, the benefits of moving things from namespace to namespace may seem insignificant -- at most, you'll win by having some private data in each and thereby encapsulate things a little.

However, this isn't where classes shine.  Consider the String class: you could have all the same features using char arrays and some static functions.  At this point, functions give you a little extra safety and syntactic sugar.  You can write string.length() instead of length(char_array); that's not a very big deal, but many people still like it.  Moreover, you know that if someone gave you a String, it was created with the String constructor and that it must work with the length function -- if the array version can't handle some character then it has no way of preventing you from putting it in there.

That's still not it, though.  The key point is that classes bundle data and functions that operate on it and abstract both of it away.  When you have a method void f(Builder b) you know you'll be getting a Builder, and you can expect that it will support certain behaviour.  However, you know nothing of data or the functions being executed -- in fact, the definitions for both may not be written yet as you write and compile f.

The first point to understand is thus that classes make it convenient to pass around data while making sure it is not broken.  The second point is that both what data and what function (implementations) an object has is something about the object, not something you can just tell from its type.


答:
Visual Studio and IIS supports MS-DEPLOY. You can read more about it here: http://learn.iis.net/page.aspx/1080/testing-web-deploy-publishing-from-visual-studio-2010-and-webmatrix/

But basically you can have different profiles for your project and different "versions" of web.config where you can transform things like connection strings, application settings, etc. to the appropriate environment automatically before it gets published.


答:
You're asking way too much from JavaScript (an interpreted language), and the amount of data you're trying to transfer will take a while to load.

The Web is not really designed for this.  Ryathal has the conventional Web solution, and if it's good enough you'll save yourself a lot of grief by using it instead of something fancier.  The browser end shouldn't be too bad.  You'll need a serious program on the server to locate and grab the right bits of the network, but you'll need that anyway.

I suspect what you want is a desktop app.  Then you can devise a fancy display connected to megabytes of data.  I'll state what I know about this approach and hopefully inspire people who know more to say something--or inspire you to stick with the conventional Web solution:

Java has its Web Start and Applets (though I've never heard of anyone doing anything big with applets), and there are ways to move an .exe over the web.  Silverlight ought to work here theoretically, as either a slicker Applet or JavaScript-replaced-with-a-compiled-language, but I don't think Microsoft intended it to be used this way.  A socket connection can move data faster than a normal web connection.  None of this will be transparent to the user (though Silverlight would come close), it will all take time to start up, and, worse, all of it will cause security problems.  If your clients are desperate for your solution you'll do okay here; your competitors have nothing better.  If you're trying to lure people away from YouTube and Facebook, forget it.

Title: Reasonable Number of Directed Graph Nodes and Edges

Body: How many directed graph nodes are typically represented in the browser? I'm working with some large data-sets with nodes and edges more then 400,000. I'm wondering if I am going down a fruitless path trying to represent them in the browser via arbor.js or similar JS libraries. What's the most effective way to allow a large number(large relative to my domain of real estate transactions, maybe 1-10,000) of users to visualize and browse a large directed graph of up to 500,000 records?</p>


问:
What actions should I not rely on the packaged functionality of my language for?
While talking with one of my coworkers, he was talking about the issues the language we used had with encryption/decryption and said that a developer should always salt their own hashes. Another example I can think of is the mysql_real_escape_string in PHP that programmers use to sanitize input data. I've heard many times that a developer should sanitize the data themselves.

My question is what things should a developer always do on their own, for whatever reason, and not rely on the standard libraries packaged with a language for it?

答:
I think you may be confusing core language functionality with features provided by extensions and / or toolkits.

I don't know of any cryptographic algorithm that pre-salts a hash for you, which is why your coworker made his comment.  But that cryptography function is not a core aspect of the language, it's part of an extension.

In general, you need to understand the tools you are using regardless of their belonging to the core language or being provided through a toolkit.

If the language says it will do X, Y, and Z upon invocation then you can trust the language to do X, Y, and Z when you correctly invoke it.  Any other result would be a bug in the implementation of that language.  That doesn't obviate the need to understand what the function is providing.

As a related example, memory allocation in C does not initialize the memory segment to a preset / predetermined value.  You generally need to then set the memory to a predefined value (such as 0x00) prior to using it.  I can trust that when I call for the alloc then the memory was allocated (assuming my returned pointer is non-null).  But the alloc doesn't guarantee it will provide initialized memory, so I need to do that myself.


答:
Like superM said, it really does depend on the language, task, and programmer. If the language (or library) is not used very often or the task is very specific, then it's less likely for bugs to be found and fixed quickly than for something that is commonly used.

Typically you'll want to rely on the language or library much more than anything hand-rolled simply because they have been tested for correctness, robustness, security, scalability, etc. etc. This is especially true these days for open-source libraries since the nature of things like Github make it very easy for random users to submit patches to fix a particular bug.

However there are rare cases where there is an issue with a language/library (less rare for languages that aren't commonly used) and in that case if you know you can do a better job, then it might be a good idea to roll your own stuff. When you start doing this though, make sure that you can actually do a better job than the existing software and that you're not just falling for the "Not Invented Here" syndrome.

Title: What actions should I not rely on the packaged functionality of my language for?

Body:
While talking with one of my coworkers, he was talking about the issues the language we used had with encryption/decryption and said that a developer should always salt their own hashes. Another example I can think of is the mysql_real_escape_string in PHP that programmers use to sanitize input data. I've heard many times that a developer should sanitize the data themselves.

My question is what things should a developer always do on their own, for whatever reason, and not rely on the standard libraries packaged with a language for it?


答:
Almost never.  There are some language features that are known to be unreliable.  Typically they are amateur attempts at providing some kind of security.  mysql_real_escape_string is such an attempt.  Do not use this.  Do not ever interpolate user-supplied values, "sanitized" or not, into SQL statements.  Use prepared statements.

Similarly, some library random number functions and hash implementations are known to be poor, or no longer secure (e.g. DES-56).  In those cases, use better third-party implementations.  Do not attempt to write your own code in an attempt to provide cryptographic security.  Do not try to write a password hashing algorithm.  Do not try to write an encryption algorithm.  If the standard library functions have been discredited, then use respected third-party code.