Learning A Language Through Unit Tests

Over the Xmas break I finally freed up enough time to do a shallow dive into Ruby via the Pickaxe book. So far it’s very enjoyable for a variety of reasons.

This is the first completely new language I’ve tried to learn after becoming test infected. It’s nice to do really simple things and keep executable tests around as a learning tool. So even very simple things like how Ruby handles escapes in single versus double quoted strings becomes



def testSingleVersusDoubleQuotes
  assert_not_equal("This line has a\n carriage return",
                   'This line has a\n carriage return')

I’ve seen Mike Clark take this approach to learning Ruby and Jeff Langr take this approach with Java 1.5, which is part of what gave me the idea.

Then there’s the shiny new toy aspect which is so far pretty obvious. Ruby is the new cool language. I think one advantage to this that I’m experiencing is that the Pickaxe book is a very good intro text to a language. I remember not really being happy recommending an intro book for Java programmers until Head First Java came out about 2 years ago.

Finally, there’s the simplicity aspect I find very appealing. Java and its associated frameworks, libraries, and tools has grown into a complex mix no one could ever expect to fully master. Ruby is at this point pretty simple. I haven’t even really looked at Ruby on Rails, but one web framework versus the plethora in Java does sound enticing.

Anyway it’s a good time of year to play with shiny objects.