Coding is not Kata

I promised on Twitter to write a blog post explaining why “kata” was the wrong word for the “coding kata” problems presented at CodeMash this past week in Ohio.

First and foremost, I absolutely loved the idea of these coding problems. The problems were very similar to those found in computer science classes (for example, find all the prime numbers between 1 and 100), but the goal was to explore new languages or coding techniques (like TDD). For me, getting to pair programming with a coworker using TDD/xUnit to solve a few coding problems was definitely a highlight of the conference.

However, as a martial artist, to me “kata” is the wrong terminology to use in this context. The correct terminology is either “coding kihons” or probably more accurately “coding kumite”.

What is Kata

There are 3 parts to the study of karate:

  • kihon (basics) – front stance, back stance, lunge punch, reverse punch, snap kick, etc.
  • kata (forms) – planned series of movements where a karateka (one who practices karate) seems to fight an invisible opponent
  • kumite (sparring) – fighting against a fellow karate student

You cannot study karate without all 3 components.

In Shotokan karate, the style I practice, there are 26 katas. The movements for each kata never changes. In other words, there is only one way to do the kata, meaning that your stances, kicks, and punches must be exact, and the timing must be correct and sincere, as if you were attaching an invisible opponent. In a karate competition, those who compete in kata are measured based upon who can perform the kata closest to perfection.

Over the course of one’s study of karate, you perform the kata over, and over, and over, and over, just like the 10,000 hours theory in Outliers. (Personally, I am not comfortable doing a kata until I’ve done it at least 100 times.) Not only does the body eventually optimize physically, but something mentally happens. You go into an “auto-pilot” mode. For example, have you ever driven to your house one day, but don’t consciously remember the specifics of the drive, because you’ve done it so many times before? This is what a karateka is trying to achieve in kata (and in kumite, and in all walks of life). The term for entering this “auto-pilot” mode is called mushin, but I digress…

The basic idea of kata is you’re trying to perfect a given series of moves via repetition. There is no deviation. Or from a Zen perspective, you’re trying to reach that state of mushin where you are in total focus and concentration, where the mind and body have become one (which is also illustrated in “kime” where you unlock your ki / chi in a split second, but I digress yet again). My first karate Sensei told me that in kata you imagine that you are fighting the dark side of yourself, all the things you dislike about your character. You visualize these negative aspects and you fight them. Thus, the more you do kata, the more your character improves.

The point I’m trying to make is that there’s a much larger aspect to kata than going through the movements.

What a “Coding Kata” would really look like

Below are a couple of examples of what I think a coding kata could look like:

Kata #1: The Implementation of Hello World in C#

 public class Hello1
{
   public static void Main()
   {
      System.Console.WriteLine("Hello World!");
   }
}
  Kata #2: The Implementation of Bubble Sort in C# (via C# online) 

private int[] a = new int[100];

private int x;

public void SortArray()

{

  int i;

  int j;

  int temp;

  for( i = (x – 1); i >= 0; i– )

  {

    for( j = 1; j <= i; j++ )

    {

      if( a[j-1] > a[j] )

      {

        temp = a[j-1];

        a[j-1] = a[j];

        a[j] = temp;

      }

    }

  }

}

And you would practice these katas as many times as possible, until you can code it wearing a blindfold or hold a conversation while coding this method.

In my opinion, coding katas are really just sample code or an algorithm for doing something. Just like a real kata, you know exactly what it is you are supposed to do. You’re just learning to repeat it over and over again, so it becomes second nature.

But, I’m not sure whether repeating these lines of code over and over again would make you a better coder. It would definitely help initially, but I’m not sure the benefits after that point. Maybe a true “coding kata” is mastered much faster than an actual karate kata.

Why Coding Kumite is a better term

Kihon is learning the specific techniques, like punches, kicks, stances, etc. In kihon, you practice these techniques in isolation, and you repeat each individually over and over and over again. To me, coding kihon would be the equivalent of learning the syntax of a language, learning lamda expressions, or learning generics. Kihon is not about solving a problem, but rather learning what tools you have available to solve a problem. Only after one learns kihon, can a karate student learn kata and kumite.

Looking at these coding problems, you could make the argument that your opponent is the problem to solve. And you’re using all your kihon practices to solve the problem, just like you would do in actual sparring (or in kumite.)

Conclusion

Having said all of this, my “Coding Kumite” analogy still falls short. I think only in debugging, where you are trying to find and fix bugs, is actual “coding kumite”. But, writing code to solve a problem still feels much closer to kumite to me than kata or kihon.

For a different perspective, you can check out Steve Andrew’s blog post called Shotokan Development. He watched my Nidan (2nd degree) black belt exam back in November, and wrote a blog post from the perspective of a software engineer on how to apply Shotokan teaching methods to software engineering.

Lastly, I’ve never experienced mushin in coding like i have in karate. Maybe someone out there has and can respond with a counterpoint to this. I’m really curious what others think, and I definitely would love to discuss these concepts further. I really think we could put together a teaching framework based on karate concepts, if anyone is interested in helping me out.

Maybe the next open spaces unconference I can propose a topic on karate terms in coding, but that’s only if Doctor Who is no longer making me need a support group. =D

Comments

  • Anonymous
    January 17, 2010
    The comment has been removed

  • Anonymous
    January 17, 2010
    I wasn't at CodeMash, but I agree that what you describe doesn't sound much like kata.  (I come from a Tai Chi background -- so-called "long-form boxing" -- but from your description it sounds like the basic theory is similar.) There are some "coding katas" around which are closer to my understanding, for example Uncle Bob's bowling game kata, http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata . I like the look of Uncle Bob's katas because they are not trivial, unlike the examples you give: I can't imagine doing even 10 repetitions of your Hello World and still finding myself going deeper into the exercise.  In martial arts katas, the more you practice a kata/form, the deeper your understanding becomes.

  • Anonymous
    January 17, 2010
    The comment has been removed

  • Anonymous
    January 17, 2010
    I wasn't at CodeMash :( but from what you're defining "kata" as is what the original intent was.  Perhaps people have taken and twisted the original idea (as is often the case... not just in the programming world).  Here's Uncle Bob's prime factors kata. http://katas.softwarecraftsmanship.org/?p=71 I think Dave Thomas (of The Pragmatic Programmers) was the one to originally coin the phrase http://codekata.pragprog.com/ likening the exercise to an etude or scales in the music world. I personally don't know if I totally agree with it or not, but I haven't really given it a fair shake yet to say one way or another. I do think that coming up with a way of incorporating the other two parts into "code" form could be interesting though.

  • Anonymous
    January 18, 2010
    I have no knowledge of martial arts, but this is pretty interesting so I'm going to dive in. I think you're right about kata not being the right word, and I definitely agree that you don't get to kumite until you're fighting against actual systems written by others. So could design patterns be considered kata? The idea of memorizing a consistent sequence and structure of your basic tools to defeat a problem seems to fit. It wouldn't be too hard to set up 4 or 5 standard problem sets for each basic design pattern, and then you could iterate on coding them up from scratch to practice. If that seems like a promising analogy, I've got some thoughts on carrying it further (and some possible problems with it), but I'd like to hear what other people think before this gets so long no one will read it.

  • Anonymous
    January 18, 2010
    Interesting article Sara, applying martial arts methods and practices to software engineering - although the word "Kata" is applied in a more general sense to activities outside of martial arts. Kata also has application in many aspects of life. A kata can refer to any basic form, routine, or pattern of behavior. In Japanese language, kata is a frequently-used word meaning “way of doing things,” with emphasis on the form and order of the process. Other meanings are “training method” and “formal exercise.” (courtesy of Wikipedia) Therefore, kata takes on a less formal meaning in regards to software engineering. Joel Spolsky authored an article on hiring programmers: http://www.joelonsoftware.com/articles/GuerrillaInterviewing3.html which has an example of three interview coding questions he gives to potential hires. The tasks ask them do perform code-kata:

  1. Write a function that determines if a string starts with an upper-case letter A-Z
  2. Write a function that determines the area of a circle given the radius
  3. Add up all the values in an array He discovered that while everybody solved the problem, there was a lot of variation in how long it took them. This is where code-kata comes in. The programmer is being asked to do a set of basic moves in a familiar pattern and is judged on timing and competency. As previously noted, Dave Thomas of the Pragmatic Programmers runs a site http://codekata.pragprog.com/ which applies kata directly to programming. Here is a great article of his on Kata, Kumite, and Koan: http://codekata.pragprog.com/2007/01/kata_kumite_koa.html Dave references the Dreyfus model of skills acquisition (http://en.wikipedia.org/wiki/Dreyfus_model_of_skill_acquisition) and describes Kata, Kumite, and Koan in this way: "The kata is rote learning, copying the master. Kumite is where you get to start applying the skills on your own. And then mastery, where you teach others, and where you use koan to attempt to discover underlying principles for yourself. I think that as developers we need all three of these levels: kata for the things we’re only just starting to learn, kumite for the things we think we know, and koan for when we want to dig deeper." While kata may not be the best description of the code-mashup, it can apply quite well to the efforts of programming. Michael McCracken @expectationgap
  • Anonymous
    January 18, 2010
    I've been training to compete in the Software Kumite! http://en.wikipedia.org/wiki/Bloodsport_%28film%29

  • Anonymous
    January 18, 2010
    OMG, I've never thought about it like that. "The Coding Kumite!" Now that's fun stuff. I might have to steal that idea one day. =D

  • Anonymous
    January 18, 2010
    Sara,  The coding dojo at CodeMash was a rather last-minute thing, unfortunately.  I agree with most of what you've written above, and as you know I'm a karateka as well.  I think if you'd been at the PreCompiler on Wednesday you would seen an actual kata in terms of a form that should be copied until one can do it perfectly.  We went through the Bowling Kata in this fashion.  In the coding dojo, we made available sample files that included the PPT with the kata walkthrough for a couple of the katas, but the instructions on making this happen were lacking.  In any event, while the name would be inaccurate, having people pairing and learning was still very valuable. The bowling kata (which IIRC was an exercise you worked on) can be found here (as well as in the download that was reference in the slideshow in the dojo): http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata Thanks for writing up your thoughts - I will be sure to make the dojo more valuable next year.

  • Anonymous
    January 18, 2010
    Hey Steve, I absolutely loved the dojo concept, and thought the pairing and coding problems were excellent. Which PreCompiler are you referring to? Sounds exactly what i needed to see. Yep, numerous people have sent me the Uncle Bob ppt. In fact, someone dropped off his book on my desk today. I just really wanted a discussion around the terminology. I'm very curious which parts you see differently. I might have to write a follow-up blog post on "Coding is Kata - Part 2" becuase i think i see a way you can say that if your body and muscle memory is like your intial code, then yes, the more you write code, the more you are finding the ultimate algorithm, just like with muscle memory. But i need to read Uncle Bob's chapter and think about this some more. Actually today, i was thinking "what would an actual coding karate class look like?" For example, if you only had 1 hour and were trying to mimic an exact karate class, what would that coding exercise look like? Something i'm going to play with this week. Cheers! -sara

  • Anonymous
    January 19, 2010
    I started writing a huge comment and decided to just make it a blog post so I could include links, etc.  You'll find it here: http://stevesmithblog.com/blog/coding-katas/ Thanks!

  • Anonymous
    January 19, 2010
    You make some great observations here, especially as it relates to the difference between practice and just solving problems. I didn't spend time in the 'coding dojo' at codemash, so I can't comment on what the situation there was. However, it is common enough for trendy terms to be taken on and reused in situations where they are neither appropriate nor meaningful. Based on Steve's comment that the coding dojo was a 'last minute' thing, it very well could have been a case of looking for any term that could be linked to the idea of a dojo. I would recommend you watch Micah Martin's talk at Ruby Conf to see a current view of what we mean by code kata, especially as it relates to internalizing the movements and performing for feedback. Micah's experiences and ideas come from his long-time experiences in martial arts, as well, and he relates them directly back in his talk. I wrote an overview of some of the thoughts and evolution of ideas surrounding coding kata over at the KataCasts site. It appears that a lot of your thoughts coincide with how we view the katas, as well. http://www.katacasts.com/?page_id=2 There are links in that post to Micah's talk, a talk I gave on practice and an example kata I did (with commentary) at the Orlando Ruby Users Group. The rest of the blog includes screencasts of katas being performed. We are always looking for guests, so, if you are interested, I'd love to talk to you about doing one. I've been using the kata idea for practice for a while now, and I can attest that there are definite benefits to practicing the same solution over and over. It takes many repititions (I think less than you've found with the martial arts kata) to really feel comfortable with the solution, enough to not really have to think about it. Coding kata aren't the only mechanism for practice, but they are a good addition. In the software craftsmanship space, we are looking at different ways to engage people in actual focused practice of fundamentals, instead of what you seem to have seen, which is just solving problems. One of the most well-received and effective practice sessions that we've developed are code retreats, where we free ourselves from the pressure of 'finishing the task' and allow a focus on the fundamentals. We'll be having one in Seattle on February 6th; if you are interested, feel free to contact me about it. I would be very interested in hearing your thoughts after looking at what some of us are doing.

  • Anonymous
    January 19, 2010
    As a follow-up, I want to make sure that my previous post was not taken as an opinion that 'practicing solving problems is bad.' It is fun and can be valuable to sit down with new people, pair up and solve established, bounded problems. That activity, though, is much different than the focused practice of fundamentals that happens in other formats, such as coding katas, code retreats and a lot of formal coding dojos.

  • Anonymous
    February 02, 2010
    The comment has been removed

  • Anonymous
    February 03, 2010
    You could use 'play/practice scales' from music. It came to my mind when reading reviews of 'Great Coders'. One of the 'secrets' is to do programming, a lot. Going for complex ones. And it's not very different from music tecnique, though you could argue if 'artist' (taking not only art, but also great performers) in programming exists, but 'scales' are just nice in this respect. And talking about great musician performing some piece for piano isn't very different from programmer. There are a lot of people with 'equal' level, but they do it differently. As for martial arts and kumite - they would rather correspond to participating in ICFP contest, from the viewpoint that you practice in solving problems applying your kata knowledge. All metaphors are broken, we all understand them in our very personal way. But programming (rather Computer Science, another arguable term) has just more than 26 kata. They could be counted, but they can be thought infinite as well. You could treat 'debugging' skills as kata, too. What is the most important thing, IMHO - you should practice. You can't get over it. And some people can practice less, and some have special abilities to performing, which leaves you envy and breathless. The result is always more than summard, whatever you take - martial arts, music, sport. Best luck.