DEV Community

John Oerter
John Oerter

Posted on • Originally published at redgreenrefactor.dev

Introduction to Code Katas

What Are Code Katas?

In the software development world, code katas are commonly used by developers
to hone their skill. They are meant to create a safe environment to experiment
and learn new techniques. The word "kata" is borrowed from the world of martial
arts.

In that world, katas are a series of choreographed movements meant to
be memorized and practiced over and over again until they are perfect. Similarly,
code katas are meant to be practiced regularly, making small improvements each
time. Code katas are usually performed using Test Driven Development.

When a martial arts practitioner masters the movements of a kata, the idea
is that he or she will be able to perform the same movements perfectly
in the real world without hesitation. The same idea holds for code katas.
The TDD flow of a kata along with its refactorings are memorized so that a
developer can perform similar refactorings and patterns in production code.

The point of a code kata is not to figure out a solution to a problem as quickly as
possible. Rather, the point is to intentionally practice the fundamentals of
writing code with TDD and using your chosen editor efficiently. Each time
a code kata is performed, small improvements should be made. These
improvements and gained efficiencies will be transferred into production code.

How Do You Do a Code Kata?

Getting started is easy!

  1. First, choose a problem or create your own.
    There are numerous katas out there that other developers have created. Some
    of the most popular are the Bowling Game,
    String Calculator,
    Prime Factors,
    and Roman Numerals.

  2. Next, choose a language. Depending on your goals, you can choose a
    familiar language or learn something entirely new. When doing a new kata
    for the first time, I would recommend using a familiar language. You can
    try new languages later after you're understanding of the kata is solid.

  3. Start coding! Remember to follow the TDD cycle:

    • Write a failing test
    • Write just enough code to make the test pass
    • Refactor
    • Repeat

Remember, this is a safe environment where you're free to make mistakes.
If you can't figure out a kata, don't feel bad about looking up solutions.
The point is to learn the movements of TDD or to practice the keyboard
shortcuts of your editor.

What Are the Benefits of Practicing Code Katas?

The three main benefits of practicing code katas are:

1. Practicing the TDD flow.

I hear that many developers want to learn TDD, but learning TDD on the job is
not always a good option. We need a safe environment to fail and learn without the
pressure of deadlines or preventing bugs. Code katas can offer that environment to
any developer that cares to improve or learn their TDD skills. Regular code kata
practice should make doing TDD in the workplace almost second nature.

2. Increased Editor Efficiency

Have you always wanted to learn Vim, but never felt you had the time? What about
all those ReSharper shortcuts? When you practice a code kata, you can take the time
to learn the most efficient key strokes and really get to know your editor. This can
really pay off when writing production code. It's a great way to increase your
confidence as a developer. Whatever editor you use, you owe it to yourself
to be as proficient as possible with your tool set.

3. Learn a new language or language features

After you understand a kata well and have practiced it a couple of times, feel free
to experiment. What would the code look like in a completely different language from
the one you use everyday? Are there some brand new features in your favorite
language you have yet to try out? Code katas are a perfect way to both learn
new languages and gain a deeper understanding of familiar languages.

Closing Thoughts

In life, fundamentals often separate the successful from the unsuccessful. What do
many coaches say after a tough loss? "We have get back to the fundamentals".

As developers, how do we practice the fundamentals of developing software?
I think this is something that our industry often forgets. We are so eager to dive in
and start slinging code that we rarely take the time to slow down and deliberately
practice to improve our skills. I believe doing regular code katas is a fantastic way
to practice the fundamentals developing software and will make a noticeable difference
in your productivity.

Originally posted on RedGreenRefactor

Top comments (0)