Skip to content

Tutorial: Create Your First Kata

Jake Hoffner edited this page Aug 18, 2017 · 19 revisions

Creating your first kata

Okay, so you might have completed many (all?) of the published katas on Codewars. But... that's only half of the battle.

There is an obvious elephant in the room: Where do the katas come from? Obviously they didn't come out of nowhere like inside a stone or from a big bang, so clearly someone, or something, must have created the kata.

Being intrigued, you looked at the Kata Creator again. Maybe you should create a kata.

Creating a kata is a totally different kind of task from solving a kata. You might be able to solve a purple kata in under an hour, and still get flummoxed by the process of making a new kata. Being a good player doesn't always make you a good level maker, after all.

While a kata with minor problems can be easily fixed, a kata with fundamental issues will get stuck in the beta process forever. You don't want that.

Use a novel/unique idea, avoid creating duplicate katas

At the time of writing, there are already over 3500 published katas, and almost 3000 beta katas. It's a vast red ocean out there - if you're still sticking to ideas like Fizzbuzz, Fibonacci numbers or Caesar/ROT cipher, it's pretty much 99.999999...% i.e 100% that someone will have done this before you.

This is bad because creating a kata about them again constitutes a duplicate kata, and we certainly don't want 100 Fizzbuzz katas out in the wild. When a duplicate is found it will be "retired", which basically means it gets taken out of the kata catalog.

Tips

Search for keywords to see if someone has done the idea before

As we all know, before you even engage your enemies, you need to send scouts forward.

For example, while Peano and Church numbers are definitely not easy, as the search results clearly shows, they've been done many times already.

In a way, knowing the katas in the wild is very similar to knowing your enemies: you get to see how others write the same kata, other people's (sometimes) brilliant solution in these katas.

Then, maybe you can decide whether to retreat, or make a harder version of the kata as return.

Use a novel/original idea

If you find yourself worrying about hitting duplicates all the time, then try to push yourself to think out-of-the-box. Don't worry, coming up with good ideas are hard! But if you can make sure your ideas are always novel and/or original, then you can be almost certain nobody will have taken the flag before you.

It also has a side benefit of making people think that you're clever, which will be reflected on the satisfaction rating.

Solve more katas

Naturally, when you've already solved 10 fibonacci kata already, solving another one will make you very nauseous ;-)

Solve more katas (again)

While the minimum honor for creating a kata is merely 75 honor, if you try to create a kata with just 75 honor, it'll most likely inadvertently be bad.

Why? With just 75 honor, you haven't even get a grasp of what katas are actually like.

Anyone can reach 75 honor in a very short time, from a few hours to a day or two. This is, obviously, far from enough. Thus, you need to train more.

Solving more kata with more experiences can help one very significantly on these aspects:

  • Getting more experienced will help you understand how hard your kata is, so that you can tune your kata to your desire easily.
  • As you train more, you tend to know what the most efficient solution for a kata is. This is crucial to performance and golf katas: you don't want to make a performance kata when you can only write sub-par solutions! You'll get pwned hard by veterans ;-)
  • Actually encountering kata issues and looking at comment sections will let you understand the common issues people will raise. Learn from the history, and don't make the same mistake again!
  • Looking at solutions (and more importantly, solution comment sections) will give you insight to what'd be good practice
  • It also allows you to see how others write their tests. Writing good tests are hard, period.

Be clear about the intent, and write good descriptions

Have you encountered that feeling when you're met with a requirement you can't understand because it's poorly and inadequately written, and you still have to fulfill the requirement?

Don't let yourself be the guy who wrote this. If you ended up conjuring such hot garbage, everyone will just keep themselves away from 10 miles away and nobody will finish your kata.

A description should:

  • Provide a sufficient and complete description and requirements of the task
  • If it provides some back-story, it shouldn't be so long that it overwhelms the kata itself
  • If complex steps are involved, given an actual step-by-step example
  • Lists all the edge cases and conditions
  • Structured well so that people can read from top to bottom as they implement the requirement sequencially
  • Putting important things (e.g round to 2 decimal places) in emphasis, e.g in bold

An extensive use of Markdown will significant help the readability of the descriptions. Codewars uses an expanded version of GF Markdown so make sure to check the documentation.

Fortunately, if your kata description is not very good, people will be eager to point this out in the comments, so you have more than enough chances to fix them.

Additionally, if you're writing performance/algorithm katas, you should provide the data range. It helps people to gauge how good their solution needs to be.

Oh, by the way, "guess your intent", or guessing in general, is seldom a good puzzle. It requires very delicate skills and experience to pull off well. If you are going to attempt this, please make sure to seek out other kata and learn from what works and what doesn't.

Stick to the intent, focus on one key thing per kata

If you ask people to do 10 katas about 10 different things, that's okay.

But if you ask people to do 1 kata which needs to do 10 different things for input 0 to 9, nobody will ever like how you require them to juggle 10 object at the same time.

This often happens for unbalanced katas - while they're asking for doing one thing, because of how the kata is written the actual difficulty lies on something completely unrelated to the proposed intent of the kata itself, e.g doing a task with a very unnatural and hard to work with input format.

If you find that your kata is too long, mostly from these symptoms:

  • your kata has a very long description
  • a typical solution is very long and yet none of them is hard, the only difficulty is from the tediousness
  • your kata requires doing many things together

, you might want to break up your kata in separate parts if appropriate.

Quoting power user @JohanWiltink's comment on one of the beta katas:

And, again, you're doing multiple unrelated things in one kata. Totally unrelated, neither of them trivial this time. What is the intent, what is the pointe of this kata?

(Please note: a pointe is not a point. I'm not implying this kata is pointless. If anything, it seems overpointed - in width, not in depth.)

Write good tests, and utilize both fixed and random test cases

While the old katas are usually lazy and only has a few tests, nowadays if you try to pull off the same trick you'll instantly get yelled at Needs random tests!!!!!11!1 and your satisfaction rating plummets to 0%.

For normal katas, a good set of tests should cover all these aspects:

  • Test basic functionality
  • Has high to full coverage
  • Covers edge cases thoroughly
  • Randomized so pattern-matching against the tests are impossible
  • Stress/performance/code tests if needed

The first three should be put into fixed tests. The fourth item should be put into random tests. The last item is optional.

You should also provide example test cases to the users unless you intend the users to write tests themselves, or such is not applicable for your kata (Example: Diffuse the bombs).

Finally, remember: just like in real life, if we failed a test, we want to know:

  • what input failed
  • expected and actual result

So unless revealing the expected result would spoil the kata, you should not hide them. Consult the testing framework and pick the best method for your tests.

...Yes, who said writing tests are easy? You need to learn how to use the testing framework properly!

Qualities a kata should have

Easy, fundamental katas

Easy, fundamental katas are intended to teach people basic aspects of programming and concepts.

Hence, in such katas everything should be clear, concise and complete. Good qualities in these katas include:

  • A well-written and concise description explaining the concept
  • Links to necessary resources
  • Good example tests

These things will immensely help people not familiar with the subject in question to grasp the concept.

Tough, challenges katas

Tough katas are intended to give a challenge to even the veterans, which are difficult to be challenged (otherwise they wouldn't be "veterans" ;-)), so one has to really go far to impress them.

Hence, a perfect, well-thought, tough kata should not just require people to code brainlessly and pass in a few minutes. It should have some stellar qualities:

  • It requires background research to even figure out the possible approaches
  • It requires careful planning to formulate a line of attack
  • Even with that, it requires hard work and clever approaches to succeed

After all, a kata is just like a puzzle, and the best puzzles are not about puzzles, they're about experiences. When you can craft puzzles that makes people experience the process of figuring it out, you'll have truly become the master.

Also, that's more in line with doing actual, tough programming tasks in real life ;-)

Random Test Cases

The community is pretty serious about writing random test cases. You can be pretty sure someone is going to complain if you forget them.

What are random test cases? They are test cases that are not statically defined. Most kata have them (except for the really old ones) and they are usually in addition to some static tests. Using both static and random test cases with make it both easy for warriors to see what they are supposed to do, as well as make it much harder to brute force a solution.

Sample Test Cases

Another thing the community is pretty serious about. They are not required, but you should provide sample test cases. These are the starter test cases that warriors will see when they load the kata. Typically authors will take their static test cases from their full test suite and copy them over here, but you can also just include a few tests to get someone started.

Old kata and kata that specifically want you to write your own tests are typically the only ones that don't provide sample test cases.

Clone this wiki locally