Programming

my faceChris Foley is a computer programming enthusiast. He loves exploring new programming languages and crafting nice solutions. He lives in Glasgow, Scotland and works as a software developer.

Ruby in Seven Languages in Seven Weeks

I recently picked up Seven Languages in Seven Weeks by Bruce A. Tate. It's a whistle stop tour of seven programming languages. Each one is chosen for an aspect of its programming model.

The languages are Ruby, Io, Prolog, Scala, Erlang, Clojure and Haskell. I've met four of them before but Ruby is the only one I've really used outside an introductory tutorial. I'm quite excited that Prolog is on the list. I've heard some good things about it and quite fancy trying it out.

Tate doesn't claim to be able to teach seven languages in less than two months. (The introduction begs you not to buy the book if this is what you are after.) Instead, he offers an introduction to the basics of each language: just enough to let him explore the programming model. The reader is expected do some independent research to progress through the book as there is no space for installation instructions or explanations for common programming concepts.

First Up is Ruby

The Ruby section starts with a little history and a brief interview with Ruby's creator, Matz. Day one covers some language basics including duck typing. Day two is functions, collections, classes and mixins. Day three is open classes, writing DSLs, macros and meta programming with modules.

Let that sink in for a moment: Domain Specific Languages on day 3 of a new language. That kind of stuff is usually left to a chapter near the end of a weighty tome.

I've used Ruby before so the early exercises were nothing new. I was glad of the refresher because day 3 was entirely new. In Java land we just don't have tools to do most of those things, at least not without spending a few weeks writing a framework first. In Ruby they were so quick and easy.

Of course, in such a lightning quick tour, Tate can only skim the surface of meta programming which must be an incredibly rich topic. I feel that working through the book has given me a little insight. I understand what some of the tools are and I can see where some of them would make my programming life easier (mixins in particular).

However, others techniques are still a bit opaque to me. Meta programming with modules is one such area and although the example in the book explains how all the parts work, it doesn't demonstrate why they are useful. After commenting out a bunch of lines in the book's example, I was left with a simple mixin, It did the same job as the original (although it went about it a different way) so I can't help wondering if a better example could have been given: something that couldn't have been solved more easily with another technique.

There is obviously something I am not seeing and the book's introduction excuses Tate from explaining it to me in detail. He's given me a starting point for independent research and that's good enough. The difficult decision is choosing between doing that research now or pushing on to Io in the next chapter.

21 September 2014

Comments