Programming Katas
How to make better code exercises
Kata is a Japanese concept that and is related to a series of choreographed movements that focus on the basic movements of some art (we usually see it related to karate, but there are also katas on other martial arts, on chado and on kabuki) while mimicking a real possible event.
A lot of programmers tried to bring this concept to our profession, trying to bring a daily practice to their lives. You'll this on Dave Thomas's code katas, on Code War's katas and even on github lists. However, one thing that bothers me is how different this code katas feels in relation to the Japanese katas that you saw above. Most of them isn't grounded on a series of steps that you learn and master them, making them better each time you practice the kata, or on an imaginary situation that you'll overcome with the kata. To help my explanation, let see it on another art, a chinese one this time. Tai Chi's Forms.
On a Tai Chi Form, each form is divided by posture. A 24 Form Tai Chi practice is divided on, you guess it, 24 postures. Each posture is something that you can learn separated and focused. Separated, each posture focus on a single detail of an art, but together, they are a full set of movements that entails the art it focus. This is true for the karate katas, chado or kabuki.
Going back to the katas, on Karate, each kata also have a fixed number of well known movements and each movement has a reason to exist. You first attack, defend you lower body, attack in a different way, uses an opening on your imaginary opponent. The point is, unlike current code katas, the series of steps to finish a kata is well know. You just need to practice them to get better at them. You already know that on movement three, you imaginary opponent will attack you and you need to counter it with movement x.
What this means is that a kata for code can't be a “take this imaginary problem and fix it yourself” exercise. If you to a karate class and learn a kata, you'll probably learn the steps without even learning the imaginary part of it. It isn’t that solving imaginary problems in they way that you want won't help you learn. But one focus on free learning, trying to learn to solve a problem using your imagination. On a kata, the focus isn't on solving the problem, but on learning and mastering basic skills. That is the reason why the steps are already predetermined. The is no freedom of choice when you practice a kata, not on karate and not on programming.
This can be seeing as a disadvantage, but in reality it's just a characteristic of a kata. This makes katas focused on specifics that you want to engrave on your mind and also short. A “do it yourself” exercise can take up from a single day to months to finish, while a kata is something that you should be able to repeat more than several times on a single day. On a Kata, instead of focusing on how can I build better apps, different architectures, connecting to a database, you focus on single lines, small implementations, a single API.
Because of that, it's important that you, be it a teacher or a student, understand where you want to get to select what type of exercise you want to practice. A regular exercise will let you free and teach you to think for yourself about how to solve a problem or build an app, while a kata will teach you a full recipe, step by step, about the focus of the kata. Going back to the martial art metaphor, imagine that katas teaches you a sequence of movements, while a regular exercise will be more like a dojo internal competition. Although there is a set of rules and limits, on a competition, you win a fight by using what you know to fight your opponent. On a kata, doing a movement that isn't on the set is already a failure.

