A couple of years ago, one of our technical architects at the Hut Group ran a few code dojos to give the team experience of TDD and Pair Programming. The team has grown massively in the meantime, so I thought it would be a good opportunity to try it again.
To quote from codingdojo.org, a dojo is:
…a meeting where a bunch of coders get together to work on a programming challenge. They are there to have fun and to engage in DeliberatePractice in order to improve their skills.
So, I booked the boardroom, setup an Intellij project on my MacBook and waited for the developers to arrive. In the end about 10 people came, with a range of development experience from less than a year, to more than we’d care to admit to.
The exercise I chose for the group was to implement the “fizz buzz” game. Basically for a given natural number greater zero return
“fizz” if the number is divisible by 3
“buzz” if the number is divisible by 5
“fizzbuzz” if the number is divisible by both 3 and 5
otherwise return the number
The first comedy moment was when we went round the table and tried to play “fizz buzz”. You’d have thought a group of highly skilled IT professionals would be able to do simple mental arithmetic, but this is apparently not the case…
The problem itself isn’t all that complicated, a decent developer could write the code in 5 minutes, but the point of the exercise isn’t really the end solution. More important is how you get to it. A pair of developers worked at the laptop. The driver types, focuses on tactics and writing clean code that compiles and runs. The navigator focuses on strategy. How the code fits into the overall design, which tests will drive the code forward, and which refactorings will improve the entire codebase.
We also wanted to build the solution using Test Driven Development. You write a test that fails, write some code to make it pass and then refactor. With a problem this simple it is quite difficult to force yourself to follow these steps.
We started with the simplest case we could think of, i.e. if you pass in 1, you get 1 back and built from there. We managed 7 iterations in the time we had available and got to a reasonable solution.
Going through the exercise prompted a lot of interesting debate. We talked about how you identify test cases, different ways of implementing the algorithm and even got into some OO design. I think the group found the exercise useful, I guess the proof will be when I see how many people come to the second code dojo.
There was one thing that I didn’t think worked too well. The navigator didn’t really get to contribute as the entire group chipped in ideas so effectively we had 10 navigators, but I’m not sure if this wasn’t a good thing.
Next time I may try using cyber-dojo which would allow pairs to work at the same time. It is a pretty neat site where you select a exercise and can code it online in a huge number of languages. One thing it does prove is that Java is a bit of a nightmare without an IDE, Ruby is the future!