Since I was facilitating it, I couldn't code during the event.
Once I got home, I did it using Clojure.
These are the tests using Midje and Clojure test.check libraries:
and this is the resulting code:
I used a mix of a bit of TDD, a lot of REPL-driven development (RDD) and some property-based testing.
Basically, the cycle I followed was like this:
- Write a failing test (using more complicated examples than the typical ones you use when doing only TDD).
- Explore and triangulate on the REPL until I made the test pass with some ugly complete solution.
- Refactor the code to make it more readable.
This way I wrote both encode and decode functions.
Once I had then working with a few examples, I added property-based tests using Clojure test.check library (a QuickCheck like library for Clojure) to automatically explore more examples by checking that the property of "decoding and encoded number returns the number" held for 1000 randomly generated examples.
I think that these three techniques are complementary and its combination makes me more productive.
To document the development process I commit after each TDD green step and after each refactoring. I also committed the REPL history.
See all the commits here if you want to follow the process.
You can find all the code on GitHub.