Thanks to all the participants for the great sessions during the spring 2007. I have now uploaded the code we wrote from those sessions to this site.
I think the Reversed Counting Code Lines Kata was really interesting. We started with code that solved most of the Counting Code Lines problem, but it was really messy, contained a few bugs and had no tests. This is the situation many of us face every day.
We started out by writing unit tests. Lots of them. It was surprisingly interesting to write unit tests for existing code when we were hunting down a bug. We had som 12-16 unit tests that covered quite a lot of the base functionality when we cought the first bug. A quick check with the coverage tool showed us which parts of the code was not tested at all. Thats a hint to be extra careful when refactoring in those areas.
With the safety net of out unit tests we started refacoring the old code. Understanding pieces of it and replacing those pieces with clearly named local functions made it easier to understand the flow of the code. Refactoring out expressions in conditional statements also added understanding and clarity.
Piece by piece the code got easier to understand and more readable. After some time we knew where to look for our bug and fix it. Then back to writing more unit tests. Finding more mugs and fixing those. The safety net of our unit tests really helped when we wanted to do more drastic things than renaming and creating local functions. It was an instant reminder when we made a change that affected something we did not think of.
In the end of the session we had fixed three bugs, created a extensive set of unit tests and refactored the code from a sloppy mess into readable, well designed code that was an excellent starting point for further development. And all this without even starting the debugger…
This exercise may be small, but is shows that there are real benefits to get from introducing unit test into existing code, and that it is not all that hard to get started.
See you after the summer for more doing while learning.
/Andreas





