Kata:a Japanese word describing detailed choreographed patterns of movements practised either solo or in pairs. -wiki

(See the code for my Change Kata)

Last Friday I started my first kata. It’s a coin change kata that challenged me to TDD my way through a program that returned the fewest coins for a given amount. I purposely didn’t look at any solutions or think about it much before I started because I really hoped the tests would drive the solution.

I was about five minutes into my first run when I knew that I was headed down the wrong path. The logic wasn’t flowing as easily as it should have so rather than fight it I deleted all the code and started again. The next time was silky smooth and a few minutes later the tests had led me straight to the solution. However, the point of TDD and code katas aren’t just to figure out a solution but to practice red, green, refactor. So I ran through it a few more times, got the thumbs up from Mike that my tests were providing the coverage I needed, and then took on one more big refactor of my CoinChanger.

All my tests passed and I was so excited I tweeted about it… which led to a response a few minutes later from Jeff Cohen asking if I wanted to come in and lead the class in some TDD and Rspec. In the same instant that I thought about how unqualified I feel to teach this stuff I remembered just how foreign all of it felt when I was sitting where the current Code Academy students are now— so I said, “sure!” When Jeff spoke at 8th Light University last week about teaching beginners he talked about how important it was to start at the very beginning and since the very beginning is fresh in mind I definitely know how to start there.

A big thanks to Jeff and the students for having me because I had a lot of fun. I started out by explaining a couple of high level reasons why a person should practice TDD and then led them through the change kata. It was my first public run through and I tried to engage the class by prompting them for the code I should write to make a test pass …and by engage I also mean screw up so that they could help me fix it (thanks Trey). After the change Kata we set up a Rails app from scratch with Rspec and ran through a few very basic tests. It was all great practice for me and hopefully the students picked up a few things.

The link at the top is an overview of the steps I took to “solve” the kata (which is slightly different from what we ended up doing in class). It’s available on Github.