Going ‘KATAtonic’

“KATAtonic” a term I picked up from Roy Osherove whilst attending his 5 day TDD course. On completion of the course one of the things that is now to become part of my daily task list is to complete as much of the decided Kata as possible in 30 minutes.

What is the ‘Kata’?

Good question, the phrase Code Kata is a term coined by Dave Thomas and derives from the concept of kata in the martial arts. A code kata is an exercise in programming which helps hone your skills through practice and repetition.Can I have an example please?
Of course, below you will find the criteria for a Calculator code kata(produced by Roy). It will outline all the functions your calculator has to perform:

Calculator KATA:

  • Takes empty string and returns zero
  • Takes one number and returns that number
  • Takes 2 numbers separated by delimeter (‘,’) and returns sum
  • Takes multiple numbers and returns sum
  • Can separate numbers when delimiter is changed \\’\n

Remember write the test first, run the tests and then do the minimal amount of production code possible to fix that failing test.

Take a look below:

public void Add_EmptyString_ReturnsZero()

Calculator c = new Calculator();
int result = c.Add(“”);
Assert.AreEqual(0, result);


So the quickest way to make this test pass is:

public int Add(string numbers)

return 0;


Now obviously this won’t work for the next test but you get the picture.

This exercise will at first take you longer than 30 minutes so stop and 30 minutes and see how far you can get the next day in 30 minutes. It’s almost like a competition with yourself, eventually (if you practice a lot) you will complete the kata sub 30 minutes. Using ReSharper, keyboard short cuts and snippets serve as a great enhancement to bringing down the time.

Give it a go and let me know what you think?

Filed under: Technical, , ,

10 Responses

  1. Martin Evans Says:

    Hi Sara.
    It sounds like a really good idea to practice this. It would be good to have a different kata published every day in a similar way that newspapers print a daily crossword!

    Posted on September 28th, 2009 at 21:08

  2. Developer Dame Says:

    Hi Martin,

    Glad you mentioned that would can't really do a different one everyday as it's all about muscle memory and repetition so it's better to focus on one kata for a period of time and then when you think you've mastered it move on to another one. What do you think about a new one every 3 or 4 weeks? Think that's something I could try and do if people would like it.

    Sara :)

    Posted on September 28th, 2009 at 21:54

  3. Svish Says:

    That would be awesome. A TDD version of projecteuler.net or something :p

    Posted on September 28th, 2009 at 22:06

  4. isaac-abraham Says:

    I'd be interested in a new one every month. Just finished bashing away on the one above, will try it out on the other people at work tomorrow :)

    Posted on September 28th, 2009 at 23:17

  5. RickardNilsson.Net Says:

    Just google for code kata and you'll find a bunch. Dave Thomas has a long list on his blog, Robert Martin as well. You can also try codingdojo.org which holds a nice kata catalogue. /Rickard

    Posted on September 29th, 2009 at 00:20

  6. johnnonolan Says:

    Just done you one and came in at just 30 mins.
    There were places where I would have done things differently and the emergent design of the red green factor rhythm was poor in my opinion. So I guess I can improve. How long do you do the same kata for? I could approach the problem in different ways (or just bash out the same code quicker and quicker)

    Posted on September 29th, 2009 at 21:40

  7. Developer Dame Says:

    I think I may not have explained the last requirement of the Kata very well. As you can see in the previous requirements the delimiter(separator) is a comma. To change the delimiter an escaped string is passed in e.g for a comma it would be \\,\n for an apostrophe delimiter it would be \\'\n so for the last requirement you should be able to change the delimiter by changing the char after the second backslash. Does that make sense?

    Posted on September 30th, 2009 at 09:25

  8. Developer Dame » Juniors – Feeling like you’re just no good? Says:

    [...] steep learning curve at the moment and that’s the reason you feel a bit lost. I try to do the Kata when I’m lacking in confidence – it’s a good reminder of your already acquired [...]

    Posted on November 18th, 2009 at 23:04

  9. Mark Nijhof Says:

    Hi Sara,

    Kata’s are a great way to flex your thinking. I just had one comment, instead of stopping after 30 minutes independently of how far you got, wouldn’t it be better to finish the kata all the time? Only that way you get to see the big picture and are able to improve early on in the game.

    Posted on December 1st, 2009 at 13:51

  10. Ciaran Says:

    On day two would it not be simpler to write out immediately as piece of code that would pass all the tests?
    I read through this particular example and knocked out the code in about a minute. Is this an over simplistic example of TDD or is it just for helping people develop the ability to iteratively improve their code designs in their head as they code them?

    PS: I’m not trying to be annoying, just trying to evaluate for myself what I would be trying to achieve.

    Posted on February 2nd, 2011 at 22:44

Leave a Reply