I’m fairly new to the term Code Kata; I haven’t read any books on the subject. Over the past few years I’ve seen them mentioned around the internet, but with the overuse of the martial arts terminology in coding — everyone’s a ninja — I chose to ignore it for the most part. When I did look into it, the ‘katas’ I saw seemed like a gimmick to sell mere coding exercises.
Kata is Japanese for ‘form.’ In martial arts, a kata is a collection of moves that are brought together for the purpose of raising and maintaining a student (or any practitioner) to a base level of competence. Sometimes a kata embodies an entire style of martial arts, so it’s far more than that simply a collection of moves, but I won’t get into that here.
Robert C. Martin (Uncle Bob) author of the seminal paper bringing together the SOLID principles, has a video series on his site — Clean Coders — aimed at educating developers towards writing better code.
In the “extras” for episode 4 Martin does the “Stack Kata” to demonstrate how Test Driven Development (TDD) can be implemented for most anything.
Watching the show feels like you’re watching Good Eats, but for coders. There are multiple personalities — all played by Martin — who argue with each other over the best way to accomplish something, there are backdrops from around the universe, his family take part. It’s endearing, and sometimes distracts from the content. Overall I would say that the content has helped me grow as a developer by leaps and bounds.
Having practiced martial arts, for years, the idea of the “Stack Kata” speaks to me. There are fundamental concepts, patterns, and principles that developers should go back to, that will improve the way they think about everything they do. With each iteration they understand the coding principles on a deeper level, which then resonates throughout the rest of their code.
The experience of performing a “basic” kata and then experiencing it on a completely different level of competence, is powerful. For that matter, when watching a master perform that same “basic” kata — you can see their mastery clearly.
According to Wikipedia the term ‘code kata’ was probably first coined by Dave Thomas, co-author of the book The Pragmatic Programmer. While I highly applaud the concept, I disagree with what he puts forward as what code katas should be.
In his intro to the concept, Thomas explains “A kata is an exercise in karate where you repeat a form many, many times, making little improvements in each.” But katas, really, are more fundamental than a mere exercise. A Kata is a ‘form’ or ‘pattern’ in Japanese — not an exercise. He states in that same intro that “Sometimes ‘kata’ isn’t quite the right word.” I think that might be because many of the ‘katas’ he suggests on that page are simply exercises, not foundational concepts.
I’m not opposed to exercises, but they don’t need to be practiced again and again. It’s very possible that Thomas suggests katas that are far more fundamental elsewhere. I personally think data structures and design patterns are prime candidates to be excellent code katas. Maybe I’m just a purist.
Test Driven Code Katas
What are Test Driven Code Katas? Well, they’re code katas done TDD style. Given the tests, you perform the kata.
What makes Test Driven Code Katas powerful are that they lay out the path to take when practicing without giving away what how exactly the code should look.
Probably the most important part of developing tests first is writing the right tests. If you are given the tests, it detracts from the practice. However, at least for starting out, there is no better guide — even better than specs — then following a proper set of tests.
I’ve been exploring fundamental computer science terminology, concepts I missed as a self-taught developer. As I go through them, I’ll be posting my katas for all to enjoy and explore.
If you’d like to share your implementations along with me, I’d love to see them. Post a link to your github repo with your implementation below the kata. If you decided to write your own tests, I’d love to see other ideas on how to approach a problem.