Code And Cocktails

TDD and REPL Analogies?

| Comments

(a half-baked thought)

In a previous post I realized that to me TDD has a little bit of the same feel as working in a REPL. When I first learned the technique it really clicked for me since I always preferred what i referred to as exploratory coding, that is, cycles of trying out little changes and moving toward the solution of the whole problem.

In a language with a REPL this exploratory coding is pretty normal. It is very natural to try something, play with ideas, and periodically save off the code you want. Without a REPL and TDD the cycle is slower, which leads to making larger changes since the cost of small changes is so high. Without a REPL, but with TDD, the cycles can be kept pretty short: short cycles of unit tests, longer cycles of integration and end-to-end testing.

So TDD gives one the ability to try out ideas quickly like in a REPL. It is not as good as a REPL. Of course TDD has other effects so the fact it is not a REPL is made up for. But, to me, the benefit of being able to play with ideas, trying lots of things, saving the good and discarding the bad should not be forgotten.

As an example of this sort of REPL/TDD based play I offer this video from Mike Feathers doing the String Calculator kata in Haskell.