Tuesday 7 February 2012

NOTE: Code Kata #1 Follow-Up

A few weeks ago I published the first in an irregular series of code katas. In a previous post I had described code katas as a form of training for programmers.

I saw a lot of interest around the post.

Richard Koopman posted an elegant response on his blog, including an additional solution for US coinage. His solution was neat, making good use of arrays and iterative coding, but my attention was also caught by Richard's home-made phone stand for his iPhone. Nice work Richard.

My old friend Dave Booth emailed me a solution that he had written off the top of his head, with no access to SAS at the time. It worked. I was suitably impressed. Dave's solution, like Richard's, used what Dave describes as a greedy algorithm. This is a very descriptive name and the Wikipedia entry offers the "coin change" challenge as an example. Dave also made a good point about handling errors elagantly:
Putting something in the code to try to trap unforeseen outcomes is a good habit to get into.
I agree, and code katas are a good opportunity to practice error trapping strategies.

Finally, Dave drew my attention to an excellent source of puzzles that could form code katas: ProjectEuler.net. The site offers a series of challenges that require a mixture of mathematical and computer science skills to solve. Take a look at the list of challenges and you'll see some good starting problems such as "Add all the natural numbers below one thousand that are multiples of 3 or 5".

In summary, don't wait for me to post more code katas. There are plenty out there on the web, and they all offer great opportunities for you to improve your coding skills.