From Taekwon-Do Patterns to Coding Katas
I spent more than 10 years of my life practicing a martial art called Taekwon-Do. I even got to compete in national and international competitions for sparring and performing patterns or "katas". So, when I first heard of "coding katas", it was a pleasant surprise. Kata is the Japanese word meaning "form" or "pattern." In martial arts, it's the choreographed set of movements that simulate combat.I have probably practiced my Taekwon-do "katas" more than a thousand times combined. I've also taught numerous students their patterns for the first time as well. But I had never done a kata in any other discipline, until I became an apprentice at 8th Light that is.
One of my assignments during the first few weeks of my apprenticeship was to watch Josh Cheek's StringScanner Kata and perform it in front of several craftsmen. As I contemplated and experimented on how to go about learning the kata for the first time and practicing the kata, I brought in some of the techniques and tricks I used to learn and practice my Taekwon-Do patterns. So, here's an account of how a Taekwon-Do black belt went about learning and praciticing a coding kata for the first time.
Learning a New Kata
When students learn patterns for the first time in Taekwon-Do, they usually follow along to a slow version of the pattern demonstrated by the instructor even though they aren't performing any of the movements correctly. Even if the instructor explains details about each movement, those details will go flying out the other ear for the new students. Thus, the first step in learning a new pattern is memorizing the movements, not understanding the movements. This should be done incrementally; the student should repeat the same steps until they have it memorized completely before moving onto the next.
When I first watched Josh Cheek's video, it looked crazy to me because he was typing so fast and using keyboard shortcuts that wrote on multiple lines at once. I honestly didn't understand what was going on when I first watched the video. Maybe I could have watched the video over and over again to understand why he typed each command but that would take too long. Instead, I watched the first 15 seconds of the video and mimicked every single thing he typed until I memorized the sequence. I repeated this process for the rest of the coding kata until I had every step memorized by heart.
Practicing Katas
Now, only a novice thinks that he is done after he memorizes the kata. In Taekwon-Do, there are a ton of details to learn about every movement and its transition in a pattern. For example, the student should understand what attack the block in the kata is blocking and from which angle the attack came from. They should understand why the weight distribution changes between each movement and how this is done. In the same way, there is much to be learned even after memorizing a coding kata. For example, in the StringScanner Kata, we write tests for eos? and the method itself. We first write a test to check if it's false when there is content left in the string. Then, we write the method and make it return just false instead of implementing the logic to make it also return true when the string is empty. A novice would have no idea why this is in the kata and might even write the logic as in the latter. However, an experienced craftsman who took the time to learn the kata in depth will know that this kata is teaching the third rule of TDD: You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
Uncle Bob suggests practicing a kata to the beat of a song in his book The Clean Coder. This is something we did in Taekwon-Do with our patterns as well. Performing our patterns to a song made us practice doing techniques in a faster or slower motion than we were used to. We would also have people perform the patterns as if they were in an enclosed box. This exercise would force the students to figure out how to generate power when they don't have the space to move their entire body. In coding, this may translate to putting restraints on memory or time. Such an exercise would force programmers to learn faster and more efficient ways to code.
Thoughts On Coding Katas
I would highly recommend anyone wanting to learn Test Driven Development to learn and practice a kata like Josh Cheek's StringScanner Kata or Uncle Bob's Bowling Game Kata. I only say this because it helped me tremendously in learning TDD. I've always wanted to learn TDD and I tried to start TDD on my own but I had a ton of doubts and questions about whether I was doing TDD correctly. I couldn't find the the answers for questions as simple as, "am I naming the tests correctly? What tests do most people start out with?" But simply watching and copying a coding kata exercise answered so many of these questions and even taught me to obey the three rules of TDD. Overall, I think there is much to be learned from the coding katas that are out there in many aspects; you can bet that I'll be looking for coding katas to practice when I pick up a new language or even to remind myself of the three rules of TDD!











