Main | Kata Twenty One: Simple Lists »

January 28, 2007

Code Kata

Background

How do you get to be a great musician? It helps to know the theory, and to understand the mechanics of your instrument. It helps to have talent. But ultimately, greatness comes practicing; applying the theory over and over again, using feedback to get better every time.

How do you get to be an All-Star sports person? Obviously fitness and talent help. But the great athletes spend hours and hours every day, practicing.

But in the software industry we take developers trained in the theory and throw them straight in to the deep-end, working on a project. It’s like taking a group of fit kids and telling them that they have four quarters to beat the Redskins (hey, we manage by objectives, right?). In software we do our practicing on the job, and that’s why we make mistakes on the job. We need to find ways of splitting the practice from the profession. We need practice sessions.

CodeKata:
A description of how this all started
MoreKata:
Sometimes ‘kata’ isn’t quite the right word; karate uses other techniques to teach too.

The Kata

What makes a good practice session? You need time without interruptions, and a simple thing you want to try. You need to try it as many times as it takes, and be comfortable making mistakes. You need to look for feedback each time so you can work to improve. There needs to be no pressure: this is why it is hard to practice in a project environment. it helps to keep it fun: make small steps forward when you can. Finally, you’ll recognize a good practice session because you’ll came out of it knowing more than when you went in.

Code Kata is an attempt to bring this element of practice to software development. A kata is an exercise in karate where you repeat a form many, many times, making little improvements in each. The intent behind code kata is similar. Each is a short exercise (perhaps 30 minutes to an hour long). Some involve programming, and can be coded in many different ways. Some are open ended, and involve thinking about the issues behind programming. These are unlikely to have a single correct answer. I add a new kata every week or so. Invest some time in your craft and try them.

If you want to discuss kata, there’s a mailing list here, and a wiki here. However, remember that the point of the kata is not arriving at a correct answer. The point is the stuff you learn along the way.

KataOne: Supermarket pricing. Pricing looks easy, but scratch the surface and there are some interesting issues to consider.
KataTwo: Karate Chop. A binary chop algorithm is fairly boring. Until you have to implement it using five totally different techniques.
KataThree: How Big, How Fast? Quick estimation is invaluable when it comes to making design and implementation decisions. Here are some questions to make you turn over the envelope.
KataFour: Data Munging. Implement two simple data extraction routines, and see how much they have in common.
KataFive: Bloom Filters. Implement a simple hash-based lookup mechanism and explore its characteristics.
KataSix: Anagrams. Find all the anagram combinations in a dictionary.
KataSeven: Reviewing. What does our code look like through critical eyes, and how can we make our eyes more critical?
KataEight: Objectives. What effects do our objectives have on the way we write code?
KataNine: Checkout. Back to the supermarket. This week, we’ll implement the code for a checkout system that handles pricing schemes such as "apples cost 50 cents, three apples cost $1.30."
KataTen: Hash vs. Class. Is it always correct to use (for example) classes and objects to structure complex business objects, or couple simpler structures (hash as Hashes) do the job?
KataEleven: Sorting it Out. Just because we need to sort something doesn’t necessarily mean we need to use a conventional sorting algorithm.
KataTwelve: Best Sellers. Consider the implementation of a top-ten best sellers list for a high volume web store.
KataThirteen: Counting Lines. Counting lines of code in Java source is not quite as simple as it seems.
KataFourteen: Trigrams. Generating text using trigram analysis lets us experiment with different heuristics.
KataFifteen: Playing with bits. A diversion to discover the pattern in some bit sequences.
KataSixteen: Business Rules. How can you tame a wild (and changing) set of business rules?
KataSeventeen: More Business Rules. The rules that specify the overall processing of an order can be complex too, particularly as they often involve waiting around for things to happen.
KataEighteen: Dependencies. Let’s write some code that calculates how dependencies propagate between things such as classes in a program.
KataNineteen: Word chains. Write a program that solves word chain puzzles (cat -> cot -> dot -> dog).
KataTwenty: Klondike. Experiment with various heuristics for playing the game Klondike.
KataTwentyOne: Simple Lists. Play with different implementations of a simple list.

There are places (apart from the comments in this blog) where you can discuss Code Kata.

The first is a YahooGroups mailing list, the second an index page on the PragProg wiki.

I have to admit that I’m nervous doing this. My hope is that folks will work on the kata for a while before discussing them; much of the benefit comes from the little "a-ha!" moments along the way. So, it’ll be interesting to see how (and if) the discussion develops.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/2226312/7674969

Listed below are links to weblogs that reference Code Kata:

» Cold Hashes from Pawprints of the Mind
So I've been reading about practicing programming, and in particular, Dave Thomas' Code Kata. In Kata Ten, he asks about a design question: hashes versus classes. Can hashes and classes be interchanged? Do you really want to? There's even a specific co [Read More]

Comments

Hi,

It seems that "15. Playing With Bits" was not transferred across. When you click on the link it returns page not found and the navigation from kata to kata skips over it as well (14 to 16).

Thanks.

James....

Thanks for pointing that out. It's there now.

Your link to MoreKata (http://pragdave.blogs.pragprog.com/Practices/MoreKata.rdoc) throws a 404. And thanks for the resource.

Thanks--got it fixed.

Most if not all of the katas are from the excellent book
"Programming Pearls" by John Bentley
http://www.cs.bell-labs.com/cm/cs/pearls/

I have to disagree with the first part of your sentence: the Kata are most definitely not taken from another source, except where credited. If there is overlap, it is a coincidence—some problems are fairly universal.

I agree with the second part, though—Programming Pearls and it's successor are indeed good books.

Hi Dave, thanks for the kata site and the great books.

It feels like there should be a forum for sharing, comparison and discussion of solutions to these and other kata. Do you know of such a site? (my simple google didn't throw anything useful up)

Max:

Have a look at the last three paragraphs of this blog entry....

haha, i forgot exam rule #1 - always read to the end of the question before starting to answer.

Dave, I've been looking for exercises like these for a long time, and am happy to find your site. But why are there no answers like on RubyQuiz? I think one can benefit very much from learning from the others. Without other solutions to compare there are several disadvantages:

* solving problems "alone" is no fun
* you don't know how good your solution is until you compare it
* you don't get different ideas

This should be a training for programmers. When I were a white belt in BJJ, some fellow blue belts showed me so many things. I think this would add much value to this site.

i love karatedo. Phil.

i love karatedo. Phil.

Hey man, thanks for the katas, it's a really good idea! Congratulations!

Post a comment

If you have a TypeKey or TypePad account, please Sign In