Imagine you’re at a Jazz club, enjoying a smooth jazz quartet. It’s time for the sax player’s solo. All of a sudden, he stops the band, rifles in a bag a pulls out a book of music theory.
“What the?!” you think.
The saxophonist looks to the audience, “I’ve just got to look up the notes for E-flat minor. I can never remember them.”
It’s understandable you’re unlikely be too impressed with this particular musician.
If you’re a musician, a sportsperson, a dancer, martial artist or anyone who practices an activity that requires skill and competence you’ll be familiar with repetitive practice.
For a musician it means seemingly endless hours of practicing scales and arpeggios to learn music theory and even more hours practicing studies to learn techniques to play your chosen instrument more precisely, more effectively, more beautifully.
If you practice Japanese martial arts you repeat kihon (fundamentals) and kata (or, as they were known in the west, flourishes) to refine your movements and skills.
Almost every activity includes these two practices alongside more creative, freeform practices. They are essential to developing muscle-memory. Without them, any creative practice will always be clumsy and immature; and there will always be a ‘ceiling’ to what you can achieve.
What does this have to do with software engineering?
The act of repetitive practice is just as important to developing your coding skills as it is to a dancer or musician. There are aspects of coding that should (and I would argue, must) be committed to muscle-memory.
In 1999, Dave Thomas, author of The Pragmatic Programmer, introduced the term code kata, in a nod to the martial arts practice.
At the International Conference on Extreme Programming and Agile Processes in Software Engineering – XP2005, Laurent Bossavit and Emmanuel Gaillot extended this idea with the paper “The Coder’s Dojo – A Different Way to Teach and Learn Programming”.
Robert (Uncle Bob) Martin has explore this concept, too, with his work The Programming Dojo.
The term code kata has come to mean a simple programming problem that is solved repeatedly, potentially in many different ways, each time either refining the solution or exploring a new (potentially better) way to solve the problem. I believe this is a vitally important part of developing your programming skills; but it lacks an important aspect of repetitive practice.
A musician doesn’t get to invent the notes of a particular scale; or the order the notes are played. The notes are given to the student and the student repeats them verbatim.
The same is true with martial arts kata: the movements are prescribed, and fixed (otherwise someone gets hurt; usually the teacher!)
The act of performing these exercises is not to repeat them until you get them right – it’s about repeating them until you can’t get them wrong! It is about committing them to muscle memory; developing unconscious competence in the movements.
I think this is an activity that is missing from code kata.
With that in mind in the next couple of articles I want to present some of my favourite C++ kata. I’ve split them into two:
- These are simple code constructs that any C++ programmer should be able to produce, almost without thought.
- These are more complex code constructs that a useful for solving common C++ problems. Often these code constructs are avoided by programmers because they either don’t understand them or can’t remember them.
These kata aren’t presented in any particular order; and you’re not required to ‘master’ one before moving on to the next.
Importantly, it should be possible to ‘mix-up’ the exercise a little bit, without changing the fundamental nature of the exercise, or what it is intended to reinforce. For example, a musician may start their scales in a different key each time. I’ve suggested ‘variations’ to my kata to mix it up a little.
In part 2 we’ll start looking at some fundamental code kata.
Glennan is an embedded systems and software engineer with over 20 years experience, mostly in high-integrity systems for the defence and aerospace industry.
He specialises in C++, UML, software modelling, Systems Engineering and process development.