Tuesday, January 9, 2007

Ruby and Smalltalk

OK, so first, my background: lots of Perl, a little Java, working with Ruby on Rails.

That out of the way, I've been playing with Smalltalk, and working with Ruby has definitely been a very useful stepping stone. Ramon Leon told me that Smalltalkers consider Ruby to be Smalltalk--, and Avi Bryant has said that Ruby is essentially a Unix dialect of Smalltalk.

I've only been playing with Ruby for a year, and only working with it professionally for about six months, and I really only began playing with Smalltalk very very recently, but so far, the two big similarities I've noticed are that the blocks in Smalltalk look very, very similar to Ruby blocks, and the object model is also very similar.

The object model in Ruby is a frequent source of confusion. Most of the hype about metaprogramming either comes from Ruby's Lispy features, or from its mysterious object model. But the object model really isn't that mysterious. A class definition is itself an instance of Class. Everything else just flows from that. As simple as this idea is, it's still very counterintuitive to a lot of people coming from other languages. (Including me, to some extent.) The dominant paradigm in OOP is the C++/Java idea where class definitions do not exist as objects themselves, and most OOP implementations -- even Perl's unorthodox and fairly lightweight approach -- conform to this paradigm. But the mechanics of Ruby's OOP paradigm are virtually identical (as far as I can tell) to Smalltalk's idea of a class side and an instance side. In a way, it's very gratifying, because, having wrestled with this a bit, I then found it immediately in the next language I learned.

Anyway, all this makes me sound very clever, so I really should point out that my experiments with Smalltalk have fallen apart a great deal. My grasp on the syntax is still pretty appalling, as I haven't yet taken the time to properly read up on it, and a big part of the reason is that all the books I've found so far are in PDF. I know lots of people prefer PDF, personally, I like something I can read comfortably on a sofa, and PDF just doesn't get the job done there. Also it's a lot harder to scribble in the margins of a PDF. There is one real-world book I'm dying to get, but until then, I still have some stumbling to do.


  1. I once worked out that it's possible to have a class definition in Perl that is itself a class (using blessed Glob references if memory serves), but implementing it at any level beyond proof of concept was a complete pain in the arse.

    And you need Smalltalk Best Practice Patterns. Even if you never write another line of Smalltalk you need that book.

  2. Interesting...I started learning Smalltalk just a few weeks ago as well. But I got Kent's book in the mail some time last week. Nyah nyah nyah.

    My initial impression is that ST and Ruby are of course very similar. The whole environment is every bit as cool as people say it is.

  3. @piers - that's kind of a perl in a nutshell, isn't it? just about anything you could ever want to do in that language is possible, but not all of it is fun.

    @pat - /me gnashes teeth and plots book theft

  4. Heh. Sort of. Sometimes hard and weird is fun though. I just don't have the patience to push it beyond proof of concept usually.

    Luckily, a bunch of people have been doing exactly that. The state of the Perl 5 art is rather different from when I made the Ruby switch; a bunch of very bright people have taken up the Perl 6 and Ruby gauntlets and have been busily abstracting away an awful lot of ugliness.


Note: Only a member of this blog may post a comment.