A little while ago, I contributed a chapter to David Greenlees’ anthology on Software Testing as a Martial art. My chapter started out as a bit of a rant against the appropriation of Japanese language by some Agilistas without having an understanding of the underlying culture. That is perhaps the least interesting part of the chapter. Having had time to reflect, I think now that the more interesting part is the musings on how the software testing industry could take an apprenticeship-type model, and by borrowing deliberately from martial arts concepts, set a higher bar for what it means to be a software development craftsman. Similarly to the purpose of kendo practice, through the practice of software development we should strive to be better human beings.
Which brings me to coding kata. Coding kata have been around for years, and whilst they share the name, most lack the very things that make martial arts kata what they are. They lack the elements that make good martial arts kata valuable. Before I get into that, let’s take a look at the kata from Kendo – the martial art that I am most familiar with.
These kata have been deliberately set up to allow the practice of very specific fundamentals of kendo. In fact, there is no movement in the kata that is extraneous. Reiho (etiquette), correct posture, footwork, balance, distance, timing, strikes and counterstrikes, recognising the opportunity to strike, observation and reading of the opponent, breathing, mental alertness – these are all deliberately built into the kata. In kendo, there are ten kata done in pairs (twenty movements to learn in all). In some older kenjutsu styles, there are many more. In any case, the kata are what they are. They do not deviate and they are the same the world over. I can walk into a kendojo anywhere and by observing two kendoka performing kata I will have a reasonably accurate gauge as to their abilities in kendo.
Contrast this with your average coding kata. You have a set of instructions, often deliberately vague and often with traps built in. There may well be a specific area to focus on, some pattern to implement or some design principle to exercise, but it is generally left to the practitioner to work out. If you’re running the kata in a group, you may focus on a particular pattern in a solution, or add novel constraints (e.g. don’t use getters & setters, adherence to SOLID principles or even ‘don’t use the mouse’), and whilst there is usually some sort of objective in mind in terms of learning, they are not deliberately put together with the aim of exercising core fundamental programming skills in a repeatable way. I think what we currently refer to as coding kata is unfortunately yet another example of misappropriation of terminology. They are more like a kind of constrained free practice which in itself is fine, but there is a richer vein of deliberate practice to mine here.
Imagine a set of kata put together to exercise the core fundamentals of programming. You could have a kata to exercise very specific design patterns, to teach refactoring, to teach various principles (DRY, SOLID, law of Demeter etc), you could even have kata for improving productivity with a given IDE. A given solution would be something repeatable; something you could drill. You could take these and use them as learning aids anywhere. Everywhere. If nothing else were to happen except neophyte programmers learned such kata by rote, that would not be a terrible outcome. You would at least have programmers who were aware of these patterns and principles.
More than this though, observing someone doing one of these kata would give you an idea of their abilities. For example, if you were hiring for a position requiring coding skills, what if you could pick any one of a number of kata and expect that the candidate knew it? Imagine you could have the candidate narrate their solution whilst coding it for you on the spot, talking about why they were doing what they were doing. You would have a fair idea of the level of the person in front of you.
In martial arts, kata are amongst other things, a demonstration of your own abilities. That makes them an excellent way for teachers to observe what lessons a student might need to learn. Most certainly they can also be a self-study tool, though a student can only really progress within the confines of their own understanding of what is correct or desirable.
Another interesting thing about coding kata (as opposed to kendo kata), is that there is the possibility of them being improved upon. An ideal solution for a kata in one language might be less than ideal in another. The term ‘ideal’ itself is open for debate. Do you optimise for performance? Speed of writing? Legibility/maintainability? Testability? Suffice it to say that one could transcend the perfectly adequate ‘standard’ solution for a kata. Indeed, if we revisit our previous job interview example, part of subsequent interview discussion might be around what changes the programmer would make to optimise for some of the qualities I mention here.
What is it that makes a kata good?
- There is a clear purpose to the kata itself, whether it be to defeat one or more opponents, or to provide working code that serves a purpose
- The kata uses a number of fundamental and advanced techniques
- Every movement in the kata is purposeful and used appropriately
- The movements can be repeated to achieve the same outcome each time
All told, a good kata provides the opportunity to practice different techniques (even if you don’t necessarily understand them yet!) as well as the ability to demonstrate these techniques to others. This makes them an excellent teaching and learning tool, provided that there is sufficient direction and correction given to a practitioner, particularly in the early stages. Perfect practice makes perfect. Without sufficiently competent guidance, a practitioner will only progress as far as their ability to recognise and correct problems. The Dunning Kruger effect will come into play here, with many practitioners thinking that speed of execution or memorisation of form is sufficient evidence of competence.
If repetition of kendo kata is anything to go by, what you will find with a well-designed coding kata is a teaching/learning tool which, when used with a broader curriculum of practice and reflection, helps programmers to learn and reinforce good coding practices and to recognise the opportunities to use them. Now for the real challenge – to put my money where my mouth is and create some.