Code Kata — Sharpen Your IT Saw
15 April 2020
Intro
The world is changing faster than ever before, and especially IT world. As software developers and engineers we should „sharpen our saw” not only to be better and better but also to be on a roll with new technologies, frameworks and libraries. The same as athletes who keep in shape and train harder to get better, faster and stronger (yup, I like Daft Punk), we should train ourselves. Staying in the subject of sport, it is also an important thing to have a good rest, regeneration, some knowledge about good techniques etc. So we can also train our skills not only by coding but also by reading technical blogs, listening podcasts, watching tutorials… but we all know that, right?
The reason why I compare programming with sport is that if we want to achieve some level of master level in both of them, we need to keep practicing. Among many other attributes, regularity is if not the most important for sure it is ONE of the most important. But ok, it’s obvious right? Some of you might say: „I code a lot at work, solving a lot of problems so I don’t {need to/have time to/put here your best excuse} code more.” So let’s imagine the lumberjack in sawmill. He is just sawing the planks — because that’s his job and he is just good at it. Every day he gets better and better! But he’s not taking any time to sharpen his main tool and it’s easy to imagine what could happen…
There are many ways of sharpening “tools” and today I want to tell you some about
Code kata
Code kata is the form of programming exercise. Dave Thomas got this word from Japanese mortal arts. There, Kata is a form of practising specific moves by constantly repeating and correcting them (yes, just like you’ve seen in karate movies). The premise of this style of learning is continuous self-improvement. Just as musicians and athletes have to repeat the same sequence of actions many times to achieve championship, so do we.
In practice, this is a task that we implement every time again, without looking at our previous solution. The goal is always to approach the problem freshly and to remember previous mistakes, try to write it again. Code kata is a good opportunity to learn from mistakes, the exercises themselves are not about the solution, but about the path that leads to it.
Example
Let’s see some sample kata from http://codekata.com/kata/kata19-word-chains/:
Write a program that solves word-chain puzzles.
There’s a type of puzzle where the challenge is to build a chain of words, starting with one particular word and ending with another. Successive entries in the chain must all be real words, and each can differ from the previous word by just one letter. For example, you can get from “cat” to “dog” using the following chain.
1. Cat
2. Cot
3. Cog
4. Dog
The objective of this kata is to write a program that accepts start and end words and, using words from the dictionary, builds a word chain between them. For added programming fun, return the shortest word chain that solves each puzzle. For example, you can turn “lead” into “gold” in four steps (lead, load, goad, gold), and “ruby” into “code” in six steps (ruby, rubs, robs, rods, rode, code).Once your code works, try timing it. Does it take less than a second for the above examples given a decent-sized word list? And is the timing the same forwards and backwards (so “lead” into “gold” takes the same time as “gold” into “lead”)?
Of course, if it’s too easy after few approaches, you can adjust it by some restrictions like mentioned time limit or adding TDD (Test Driven Development) approach. Still not a challenge after few approaches? Try without libraries you used before, try different languages, other environment… There are so many possibilities that you can look like
and it’s only one of many katas. You can modify it as you like. Now, there may have been a question
Where to start?
There are a lot of places on the internet, where you can find katas. Already mentioned codekata.com have classical katas and explains the basics. On reddit.com/r/dailyprogrammer/ (yes, it’s not only for memes and stuff) we have a lot of challenges with mentioned difficulty level and large community involvement, same as on www.codechef.com. If you like rankings, gamification and competition, I recommend app.codesignal.com, codingame.com and codewars.com. Last one have integration with github if you like to share your scores. Of course, there are a lot more!
Summary
Few months ago, I had presentation about code kata in Evertop. Now I know, that some of my colleagues from the company are positive about this form of “sharping their saws” and I hope, after reading this text and give it a try, you’ll also find that it’s worth it. Just remember, if you stand still, you are actually going back.