How do you decrease the number of bugs in your software to the minimum? That’s the question that probably worries all code-writting folks out there. Considering that the issue of bugs can be pretty personal (that is, the bugs occuring in one developer’s work might not be likely to occur in the other’s and vice versa), it’s hard to come up with and outline the most important bug-decreasing tips.
But it’s worth trying, like Patrick Smacchia did over here. He lists his own seven ways to minimize number of bugs in the software.
The seven are:
Contract
The idea of contracts is to insert correctness information inside the code. When contract is violated it means that your code contains a bug somewhere…
Automatic test
…having a solid battery of automatic tests is an excellent way to decrease significantly the bug rate on tested code, but also to avoid new bugs when code gets refactored.
Empirical approach
* Most of bugs in a new version are coming from modified code and brand new code
* Unchanged code that works well for a long time in production won’t likely crash within the next release (what we call stable code).
Code review
…focus your review on not stable code, i.e added code and modified code. If you release new versions often, the mass of code to review before each release will quickly become an epsilon of the size of your entire code base. Doing so can also be seen as a way to capitalize on code reviews made during previous iterations.
Prioritizing bugs fix over new features development
This popular methodology directly results from the concept of stable code. Prioritizing bugs fix over new features development can be seen as a way to constantly struggle to maximize the surface of stable code in our code base.
Programming style and code quality
The recent buzz around LINQ or F# comes from the fact that object style programming is more bug-prone than functional style programming. This fact results from the expressiveness of functional style. In other words, functional code is easier to read and understand. A major aspect of the expressiveness of functional programming style is IMHO the concept of immutability that I described in a previous blog post Immutable types: understand their benefits and use them. That’s a fact, it is hard to write, understand and maintain code that mutates states at runtime (for example this is why global variables are so harmful). And this becomes much harder in concurrent environment.
Obviously, code quality has also a direct impact on code correctness. Anti pattern such as methods with high LOC, high Cyclomatic Complexity or high Nesting Depth, entangled components, methods with multiple concerns, classes with multiple responsibilities… leads to code harder to debug and to test.
Static Analysis Tools
…to be efficient, a bug finder static analyzer needs to be feed with more information than just the code. Typically, this extra information can be found in contracts and unit-tests code.
And in proof of Bugs being a personal issue, here’s another post reflecting on the seven listed points, where the author gives his own version of the main anti-bug technics.