Join the DZone community and get the full member experience.Join For Free
For some reason this whole Code Kata movement passed me by, so I'm coming late to the party, but I'm getting hooked.
The term kata comes from Japanese martial arts and means "detailed choreographed patterns of movements practiced either solo or in pairs" (wikipedia). The intent is to practice and practice some sequence of movements until it becomes second-nature, flowing, and effortless. Repetition, practice, training.
When applied to programming, it's the same intent. Every day, you take 30 minutes or so and and write some code; the same code every day. It's like practicing scales when you learned how to play the piano: every day you'd repeat the same scales, getting better at doing them, polishing, polishing.
The object is not necessarily to think of different ways of implementing the same solution, but to practice writing the same implementation from scratch every day, and throw everything away at the end of the session. You are learning your development tools through repetition; you are rehearsing your basic programming skills; you are not writing code for posterity.
Many code katas emphasize TDD. That is, once you've worked out the solution to your kata problem, you work through building it test-first and practice doing it. Perhaps you'll see different ways of working your way through the red-green-refactor cycle and slowly modify your approach. But again it's not particularly about that, it's about rehearsing your coding abilities for a certain set time every day, no matter what else happens that day.
I was talking to my old friend Maxx about this recently because we were both bemoaning the fact that we hardly program any more, and we really wanted to get back into it, to feel the Zen of being able to write code quickly and effortlessly. This is one way to prepare ourselves for that.
For some examples of code kata, check out these sites:
- Dave Thomas' Code Kata site with 21 kata ideas on the right sidebar. Dave Thomas is one of the Pragmatic Programmers, of course.
- "Uncle" Bob Martin has a couple of good examples: the Bowling Game Kata (which is actually quite difficult to solve elegantly in the first place, I think), and the Prime Factors Kata.
- Roy Osherove has a fairly simple kata designed to practice those TDD skills: the String Calculator Kata. There are several solutions shown in different languages: feel free to copy them (after all, the point is not to shown off how clever you are in your solution — you're doing this for yourself, remember).
Published at DZone with permission of Julian Bucknall , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.