Ruby 'til 6

Posted by Piers Cawley on Aug 8, 2006

Oh, I say. It seems that Sam Ruby is another member of the “Ruby ‘til [Perl] 6” club.

I like Ruby a lot. For the kind dynamic OO/Functional coding style that I espouse, it’s a better Perl than Perl simply because it’s so much less verbose (I got so tired of always unpacking the argument list, it tended to put me off applying the Composed Method pattern anywhere near often enough).

But it’s not my One True Language. Perl 6 looks like it might be an awful lot closer to it. If nothing else, it has Lisp style macros.

A good macro system, especially when it’s combined with an accessible and well abstracted runtime is an awfully useful thing. For instance, consider the Rails controller. In a rails controller, public methods are ‘visible’ as actions that can be accessed via the web (usually with a url of the form /:controller/:action). Protected and private methods aren’t accessible in the same way.

But sometimes it’s quite handy to have a method on the controller that shouldn’t be deemed to be an action, but which you might want to call from a model. The canonical example here is when you’re doing Double Dispatch. Here’s an example of bad code: