Code Worrier

Teaching myself to RTFM

Code Kata and the Kata Gem

| Comments

A code kata is a small programming challenge on which a developer can practice her craft. Kata have solutions in the sense that they set our requirements that a program can meet or fail to meet. However, it is the process of thinking through the kata—and perhaps implementing it multiple times in different ways—that is intended to provoke learning.

Of course, you can’t learn anything form a kata unless you do the kata. Enter the kata gem by Wes Bailey.

I learned about the gem from a lightning talk Bailey delivered at the inaugural Steel City Ruby Conference in Pittsburgh. (Incidentally, SCRC was my first programming conference, and it was fantastic. My experience there inspired this blog.)

The kata gem reduces the friction between you and actually sitting down to do kata. It accomplishes this by presenting the kata requirements in bite-sized pieces on the command line. The process of working through a kata via the gem resembles the work flow of test-driven development. (To be clear, working with the gem in no way precludes actual TDD.) This is no accident; Bailey’s DSL for authoring kata is modeled after the Rspec testing framework.

Here are the first two steps of the calculator kata, which asks the coder to create a Calculator class, instances of which are initialized with strings of numbers:

Create a calculator that is initialized with a string expression
- detail: The expression is of the form digits separated by commas: "1,2"
- detail: The expression is accessed by a method named expr
- detail: The expression can be reset for evaluation at any time without re-initializing
- example: "1,2"

Add Method
  Create an add method that sums the string expression
  - detail: The method will return the sum of the digits
  - detail: The expression can contain 0, 1 or 2 numbers
  - detail: Then empty string will return 0
  - example: "" computes to 0
  - example: "1" computes to 1
  - example: "1,2" computes to 3

…and so on. Yes, things start off simply, but simple problems allow for focus on technique and experimentation. In my next post, I’ll relate something I learned by experimenting with the calculator kata.