Learning a New Programming Language with Code Koans

For an experienced programmer, learning a new programming language can often be a frustrating experience. Most tutorials are written with a burgeoning programmer in mind while the reference documentation is generally too large to be useful while learning the basics.

One very useful form of coding exercises that teaches different language features like syntax and structure are code koans. A koans are essentially a simple problem where programmer is asked to “fill in the blanks”. They look a lot like unit tests and will be immediately familiar to those programmers that are used to writing them. There is a number of koans ready to be pulled from internet like these in Ruby and Clojure. These koans are not to be confused with hacker koans, which are more like parables that depict coders being enlightened.

Here is an example of a Java 8 koan demonstrating the new “parse” method on a LocalTime class in java core API:

Available here. Learn more here.

I’ve been using koans for a while now in workshops with teams that are new to a certain programming language and needed to brush up on some language features. Recently, I decided to go over new Java 8 features in a more systematic manner and thought of going through a set of koans. However, I couldn’t find any koans ready for me to use. So I decided to write some myself. Writing koans actually proved to be a much more entertaining and overall better learning experience then solving them. Not only do you have to think about how a particular language feature works, but also about how to demonstrate it in a succinct manner. So, if you are learning a new programming language, try solving some koans and if none are available I suggest you write and publish some yourself.