If you have adopted agile development methods, or even just interested in them, Dr. Dobb's published an article Test Driven Development: Does writing software backwards really improve quality? where they tried to evaluate if Test Driven Development (TDD) really improves code quality. The article shows that TDD helps to have less critical (none where found by the QA in the article's case) bugs and less bugs in general. The developer's feedback - the one who wrote the code used in the evaluation - is worth the reading:
- The TDD code was refactored several times during development. Methods were created, then changed, and then changed again with each revision, resulting in code that was tighter or clearer. The developer felt like the code went through an extensive proofreading cycle similar to what is done for newspapers, magazines, or the like.
- There was a freedom of experimentation that led to better design decisions. Once the first working version of a class method was completed and properly tested, the developer could then try new design ideas. The unit tests quickly confirmed or denied that the new code worked, providing a digital safety net.
- On a number of occasions, the developer found that the TDD method forced him to slow down and think more carefully about what he was trying to accomplish. Rather than just banging out code to get the job done, he focused on writing high quality code.
This encourage me to try it in my current projects :). As they say in the introduction, writing tests before the code is not so natural ;) at first sight, but it could be fine to spend less time on bug squashing by taking some additional time to write the unit tests before.


