Posts Tagged ‘Kata’
Monday, October 12th, 2009



Since attending Roy Osherove’s TDD Master Class I have been doing my daily TDD Kata, I will admit I have missed some days but generally I have been keeping up with it and really seeing the benefit.

Here I talked about what a Kata is and how it compares to Kumon Maths and I also took the opportunity to practice my reviewing techniques by looking at the best and reviewing Uncle Bobs prime factors TDD Kata.

I had promised to provide a web cast of the TDD SharePoint session that I did at the Best Practices conference, but I feel now that I need to really improve my keyboard mastery before taking on that one.  Instead I have taken the opportunity to record my current TDD Kata which is based on Roy Osheroves String Calculator.  I have limited the steps I have done in this recording as I think 30 minutes would get a little boring.

String Calculator

  1. Create a simple String calculator with a method int Add(string numbers)
    1. The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example “” or “1″ or “1,2″
    2. Start with the simplest test case of an empty string and move to 1 and two numbers
    3. Remember to solve things as simply as possible so that you force yourself to write tests you did not think about
    4. Remember to refactor after each passing test
  2. Allow the Add method to handle an unknown amount of numbers
  3. Allow the Add method to handle new lines between numbers (instead of commas).
    1. the following input is ok:  “1\n2,3″  (will equal 6)
    2. the following input is NOT ok:  “1,\n” 
    3. Make sure you only test for correct inputs. there is no need to test for invalid inputs for these katas
  4. Allow the Add method to handle a different delimiter:
    1. to change a delimiter, the beginning of the string will contain a separate line that looks like this:   “//[delimiter]\n[numbers.]” for example “//;\n1;2″ should return three where the default delimiter is ‘;’ .
    2. the first line is optional. all existing scenarios should still be supported

 

The idea behind TDD is to work through one thing at a time,  so in the example we start with 0 numbers (or empty string) and progress through each requirement continuing to adopt the Red, Green, Refactor approach – hopefully this will be clear from the video.

The Kata is not about knowing how to solve this problem, it is about knowing how to do things quickly and also knowing how to approach problems using TDD. 

In this example,  as in my day job, I am using ReSharper to aid refactoring,  NUnit 2.5 for my tests as this supports TestCase and TestDriven.Net to run the tests.

I have setup some live templates for the Test method and common Assert.AreEquals statements and have added a Keyboard shortcut to Re-Run the tests in TestDriven.Net (I use Alt + R).

Hope you enjoy the video, I have left the sound off - if you perfer some nice background music I can edit and add some :)

Would love to hear your thoughts on this.

TDD Kata – Calculator Part 1 by AndrewWoody from Andrew Woodward on Vimeo.

You can download the WMV video to watch locally from the Vimeo site.

Sunday, September 27th, 2009



Last week I had the pleasure of attending Roy Osherove’s Test Driven Development Masterclass,  I will post in a few days more on this but can say this is one of the best training courses I have ever attended.

During the course I got to learn about the Kata technique, something I had heard about but had never investigated.

Kata is a Japanese word describing detailed choreographed patterns of movements practiced either solo or in pairs. most commonly known for the presence in the martial arts.

The theory is that if you practice a common technique regularly (every day) over time the actions will become natural and automatic, you will have muscle memory.  During the course Roy introduced the idea of coding a reasonably detailed solution, using all of the good TDD practices (Red, Green, Refactor), every day so that the techniques used become second nature, the act of coding something using TDD is natural.

Over the course of the week the class went from being unable to code half of the problem in 30 minutes, to being able to complete the solution.  The obvious productivity’s aside, I will discuss this in a future post, it was clear that every developer in the class was able to master a new technique.   In fact I have tweeted with some of the class members who were doing the same code Kata on Saturday morning.

So what does Jack do?

Although he did join me in my Sunday morning Kata I am not saying that Jack has been doing these coding Katas for years. No, Jack has been doing Kumon mathematics since he was 4 years old. 

Kumon is a math and reading enrichment program. Students do not work together as a class, but progress through the curriculum at their own pace, moving on to the next level when they have achieved mastery of the previous level. Mastery is defined as speed and accuracy.  They only progress when they have mastered the skills through practice and repetition.

Kumon sheets (numbers of questions) are completed daily, they build up the students skills in mental arithmetic and techniques by repeating them often.   Jack, like all new students, started at a level that is below their current ability but through which they can quickly progress.  Jack started at level 6A and moved quickly through the numbers bonds and now has an amazing ability to do mental maths.  Although challenging at times Jack has continued with his daily Kumon (KATA) and had reached the G-League before starting high school, an amazing achievement.

So I can now say that Jack and I will be doing our daily Kata together,  perhaps aiming to master a different art, but taking a daily step closer to achieving that mastery.

Kata is definitely something that will become a way of life for people at 21apps, the value is real and measurable, the personal satisfaction is infectious.