Code Katas
In this post I want to talk about code katas. Most of you have heard of code katas before, many of you probably have done some katas. A while ago code katas were getting a fair bit of attention. Including of course some skepticism.
Just in case you haven’t heard of code kata yet, let me explain briefly. The term code kata is coined by Dave Thomas, co-author of The Pragmatic Programmer. It’s a bow to the kata concept in martial arts. Kata is a Japanese word and literally translates to form. Originally kata was a training method to help a student master a specific move or technique.
The intention of code katas is to help programmers to master just that: master a specific move or technique. To practice these we use simple algorithms that we can dream up at any moment. Think of sorting and prima factor calculation.
So what’s effective about these code katas? I mean coding up the same algorithm time after time just doesn’t seem like you practice any technique. Except maybe your typing skills. This is why skepticists will tell you that katas are not effective and no more than a waste of time. Solving the same set of programming problems doesn’t make you a master programmer.
And they are are spot on. Solving the same set of problems with (almost) the exact same code time after time doesn’t help a bit towards mastery.
Yet I totally believe that katas can be a very effective way to practice. Just not by coding up a solution to a problem in the same way over and over again. On the path towards mastery you will have to find many ways of solving problems, not just one. A kata is not about the solution to the problem. It’s about the path of how you get to the solution.
How many ways can you think of to calculate a Fibonacci sequence? In what forms can you code a bubble sort? And a quick sort? There’s no need to learn these algorithms, you probably can dream them already. Instead you focus on the code you use to get you there. You’ll walk along a certain path until you master it. You make little tweaks to the way you code up the solution along the way. You carefully consider every step you take.
To me this is what katas are really about. I often use katas to practice and learn. Again, not about the solution, but about the path. My path. The way I code. Katas help me to challenge each of my steps along the way. Is this next step the best I can think of? Why this step? Why not another? By challenging every step on my way it’s almost like pairing with myself. As a navigator I can pick up important feedback.
Then I find code katas also particularly useful for learning a new language. The famous Hello World asserts that my installation works and I can write a main. Next I want to feel the language. By doing a few katas I can get a decent grasp on its syntax. Then I want to explore some of the language’s unique features. Because I’ve seen many solutions to the katas in various languages I can get a feeling of what the language has to offer.
That said, katas are not the only way to practice and to learn. Many programming languages now have a set of koans available, to help you learn the language. I find these are very useful, too. And most katas are useless for learning more about a particular library of framework. Which is not the point of katas anyway.
As you can read, in my experience code katas help me practice and learn. Yet I completely agree that doing katas by coding up the same solution over and over again, is a waste of energy. I want to reiterate that it’s not about the solution here, it’s about the path. Most of the time I delete my code directly after I finish a kata. The lessons I learn from walking the path remain in my head and I won’t ever look back at the solution. The exception here is the first few katas I do in a completely new language. Before I have the syntax in my fingertips, sometimes I find it useful to look back at the previous exercises.
If you’re interested there are a lot different katas out there. Google is your friend. To get started you can use this Kata Catalog.