Spike to learn, TDD to build

I don’t consider myself a coding genius, and as my brain is fairly small when I start on new programming problems, I invariably come across things that I don’t know how to solve. Just recently I’ve been looking at using POI to read some Excel files. I started building the code in my normal fashion using TDD and ended up getting myself into a horrible mess.
The reason was that I didn’t know enough about what I was doing to write the tests to drive the design. In the words of Obi-Wan, These are not the tests you are looking for. I spent a lot of time going nowhere because I didn’t know where my goal was. So, I deleted all the code and started again. This time I started by creating a spike. This is essentially a single vertical slice of functionality through what I wanted to do. I didn’t write this TDD, I just wrote code to explore the landscape. I wrote code to learn what is possible, and what is not possible. This code does not end up in a production system, but it gives me all the information that I need to know to build the code properly. This is almost the case of “build one to throw away”.
After spending a relatively short time exploring the capabilities, I was in a much better position to use TDD to drive me to a goal, and the resulting code was much cleaner and had a better “feel” about it. New functionality was added in a more natural way.
There has been discussion on the Yahoo! extreme programming list about “when do you not use TDD”, and this is one of those cases for me. I don’t use TDD when I don’t know what to do. This makes sense to me because TDD is a design activity, and if you don’t know how to design something, you need to have a better understanding of the problem (and solution) domain or you’ll end up in a horrible mess (see above).
Of course, this is not for everybody, some people may prefer to walk away and spend some time using UMLAsSketch to solidify their thoughts and understanding. However this approach works nicely for me, and if you’re having trouble getting TDD to work for you this may provide a helping hand.

Advertisements

3 thoughts on “Spike to learn, TDD to build

  1. TDD

    Jon Eaves :
    I started building the code in my normal fashion using TDD and ended up getting myself into a horrible mess.
    The reason was that I didn’t know enough about what I was doing to write the tests to drive the design.
    I find this is a

  2. re: Spiking and TDD

    Jon – Six Million Dollar Man – Eaves raises some interesting points on spiking versus TDD. A very good summary on a tried and true approach for learning new stuff. While I agree totally with the article (I do this…

Comments are closed.