Monday, November 15, 2010

Project 1 Lessons [Coding Katas]

A few weeks ago a colleague and I took to center stage as we launched another lunchtime activity for our project's crew.

There were a few differences from the lunch and learn initiative, not the least of which was the voluntary nature of attendance. We also wanted to engage the audience with a bit more than a presentation. Perhaps worth noting, each of these goals came after the superb interest generated from casual mentioning of coding katas by friend of the blog and resident Bearsharktopus fan Chris.

Bearsharktopus Projection

The Task

CodingKata.org is a great resource for programming problems that build skills. In our case, we were using the simplest suggested problem as a way to teach Test-Driven Design (TDD). FizzBuzz was proven to be a great way to illustrate this very important concept; certainly much easier than a 10-year-old codebase.

The FizzBuzz problem is apparently adapted from a drinking game and is a frequent cast member of programming interviews. There are just five requirements:

  1. Run through the numbers 1-100
  2. If the number is divisible by three, print "fizz"
  3. If the number is divisible by five, print "buzz"
  4. If the number is divisible by three and five, print "fizzbuzz"
  5. Otherwise print the number itself

The Demonstration

Our plan going in was to switch out pairs of programmers every five minutes. Being the truly agile adopters we are, we went with another approach that seemed to flow naturally with the event -- keyboard passing.

Chris and I began with the way all good programs begin: writing a test that fails. He first asserted that our result, given a number, would return a string. Then I made it pass and wrote another test.

Soon we had almost all of our client developers writing tests and making them pass. The approach won praise and has since been requested again by those involved. Katas will definitely be on the docket for any of my projects.

Fun Fact Bearsharktopus is an Internet meme

Fun Fact There is no right answer to FizzBuzz. An "enterprise" solution is hosted on Google Code.

Yikes! Moment FizzBuzz is apparently an easy way of weeding out 99.5% of those who apply for programming jobs. Source: Coding Horror

No comments:

Post a Comment