While communicating with people on forums, I noticed there are a few lasting misconceptions concerning the static analysis methodology. I decided to write a series of brief articles where I want to show you the real state of things.
The second myth is: "Expert developers do not make silly mistakes that are mostly caught by static code analyzers".
This is how this statement looks in discussions on forums (this is a collective image):
I, a skilled developer, haven't had any problems with memory spoiling, object lifetime, etc. for N years. Static analysis is a tool for "McDonald's", and here (on a professional forum) there are only geeks. Now I mostly face problems with difficult-to-test algorithms and integration with other developers using implicit contracts on object states.
It sounds as if typos and inattentive mistakes were solely the work of amateurs. Professional developers have not made them for a long time and now mostly deal with such complex errors like synchronization issues or complex data processing algorithms.
It is not so. All the programmers make silly mistakes. I know that you haven't heard me, so I repeat this heretical thought once again: all the programmers make silly mistakes. It doesn't matter how skillful they are. To err is human. Errors they make are most often very simple.
Programmers take my statement about errors with great unfriendliness. In their opinion, they are those who haven't made such mistakes for many years. I think it is the effect of an interesting aspect of our psyche that sifts memories about unpleasant moments of the programming practice.
Let's digress from our subject a bit and recall why various horoscopes are so enduring. The first reason is very vague formulas that one can easily apply to oneself. But we are interested in the second point: people do not remember cases when a prophecy didn't come true. But they do remember and tell the others about those cases when some situation in their life coincided with one described in a horoscope. So it turns out that when we speak about and recall horoscopes, we find N evidences that they work and do not remember about N*10 cases when they did not work.
Something like that happens to a programmer when searching for errors in code. You remember complex and interesting errors very well and can discuss them with your colleagues or write a blog-post about them. But when you notice that you have written 'BA' variable instead of 'AB', you will simply fix the bug and the fact will slip from your memory. Freud noticed one peculiarity of our memory: one tends to remember positive statements about oneself and forget negative statements. If a person fights a complex error in an algorithmic task, when he finally fixes it, he considers himself a hero: this fact is worthy remembering and even telling the others. But when a programmer finds a silly bug, there is no reason and wish to remember it.
What proofs do I have? Although most misprints and bugs get fixed finally, some of them remain unnoticed in programs. A lot of examples of these you may find in this article. You will see that it were not novices who made the mistakes cited in the article, but skilled programmers.
The conclusion is: programmers spend much more time on fixing misprints than they think. Static analysis tools can help to significantly save developers' efforts, detecting some of these errors before the testing stage.