Olli Lehtola17. Feb 2013

I've been doing the Roy Osherove's string calculator TDD-kata in:

  • PHP
  • Java
  • C# via Mono

I'm starting to get the hang of coding TDD style and it certainly gives you nice degree of trust in your code. This is something I'm propably going to use in some work projects. C# and Java have been the most work as at work we use only PHP and I haven't really done much with C# before.

Basically after the first go-around I had working code in one method and had tests covering. The real eye-opener was when I refactored the one method into more reasonable pieces. The unit tests provided very nice safety net, so I knew that my program still works as specified even after modifications. Naturally one move after refactoring would be to add tests to cover those additional methods.

With legacy PHP code where there is no automated testing at all, the refactoring required for TDD makes it propably non-starter. I guess the correct way to proceed there would be to write all the new code with tests and perhaps upgrade the old code in small pieces when changes are required.