Wednesday, March 3, 2010

Prime Factors Kata

(Cross post from IRefactor)

One of the key aspects of a Software Craftsmanship is constant practice.
Kata (from Martial Arts) is one form of such practice. The notion of a Code Kata was first introduced by Dave Thomas and can be viewed as:
  • Practice of the same methods, solutions and activities to a perfection.
  • Practice of the same problem, tackling it each time from a different angle or with a different solution.
Solving a known problem multiple times utilizing the same methods, enhances the understanding of the specific steps; It especially enhances the understanding of unit tests, refactoring steps or "Design" approaches. Moreover, striving to do better each time motivates one to learn the keyboard shortcuts and IDE commands in order to perform smoothly. Knowing the tools of the trade (or the tools of the Martial Arts :) ) is essential for the Software Craftsman's success.

Solving a problem in different methods helps to identify solutions that work better in the right context (requirements).

Below (also here) is one of my Prime Factors Kata's sessions recorded late at night :).
The Kata demonstrates finding a number's prime factors using TDD (C#, NUnit, VS 2008).
(Don't forget to turn on the speakers)

I must admit, that it is super difficult to record a completely clean demonstration, especially while synchronizing the music and the moves. Moreover, one of the real obstacles is statically typed languages (C#) that slow a bit the moves. Exercising the Kata with dynamically typed languages can ease and speed the performance.


  1. Neat :D

    Do you have a Kata that convinces developers they need to design / refactor / test?

  2. Thanks :)

    Kata supposed to be a short exercise without any explanations, so I am not sure how much it will convince.

    I do have Katas for Refactoring and Design, though it sure will take me time to record and post :)

    In the past I did several talks about Refactoring (+ Refactoring/Design) and I expect to do some in the future. During those lectures, I hope :) I succeed to convince developers at least to start and utilize some of those techniques:

    In addition, I hope to organize a first local Software Craftsmanship Group next month. The purpose to have monthly or bimonthly meetings of a community that can influence and enhance the professional software developers.

  3. Thanks for posting your kata. I enjoyed it.

    The only request I have is that for the next one, before you start, would you state what task you will be coding (for example: "Compute the prime factors of n") ? I was confused at first because I assumed you were solving a different problem related to primes.

  4. Very nice :) It's interesting to watch uncle bob's kata in C#

    Did you consider posting it on kata cast ?

    Also, I was wondering what's the background music? :)