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:
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()
Kata #2: The Implementation of Bubble Sort in C# (via C# online)
private int a = new int;
private int x;
public void SortArray()
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.)
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