2005-11-30

A Ruby in the rough

I've noticed in the past few months more articles in the nerd channels about Ruby (mostly in regards to RAILS which I don't use). I'm sure it's simply selective attention on my part because I really love Ruby, more fervently than I did Perl when I first started using it some 10 years ago.

Ruby is a scripting language and I've been using it nigh unto a year now. It is currently my favorite scripting language and it was so practically from the first day I started playing with it. You can find plenty of advocacy, zealotry, demogoguery, and fanatacism in the usual places online; I'm sure even more if you can read and understand Japanese. Fortunately for me I did not see or read any of that online bantering about how "my scripting language can beat up yours" when I decided to play with it, only enough about it to give it a try.

Two things sold me on it immediately:
  • Nice data structures
  • The presense of "=~"
I'd been a Perl die-hard for years, was forced to use Python for work reasons, learned to really appreciate Python for what it was, and then cursed both for not having what I liked and needed to have in each. Perl makes for great quick-and-dirty guerrilla-warfare scripting but became clumsy for larger projects. Python was systematic, clean, and good for such larger projects, mostly due to its data structures, but it really dropped the ball when it chose not to add that little simple piece of syntactic sugar ("=~") to handle regular expressions. I deal with lots of text data but even if I didn't I do consider regular expression tools a basic necessity to life on the command line. And using regular expressions in Python just blows! There are other annoyances in each but those are currently of primary importance to me and my trade.

Enter Ruby, which upon first encounter appears to have the best of both worlds. Oh joy! I got busy with it immediately. It also had an interactive mode like Python, something Perl really needed. With a bit more experience, I discovered and began to appreciate some of its other and even novel features:
  • Truly object oriented in presentation (even the number 1 acts like an object) which adds a kind of consistency.
  • Interesting use of code blocks (I didn't like lambda's in Python, does anyone?).
  • Ease with which to extend even basic classes and objects.
With more use I found myself rethinking my former ways of coding a task (e.g. I found myself considering even simple things more often in terms of iterators). There are also things I find truly elegent (e.g. using code blocks for initializing).

The unfortunate aspects:
  • It's still rather new (outside Japan) and so the community and support is rather smaller than Perl and Python.
  • The syntax and keyword naming is a mite unfortunate and takes some getting used to. But at least it doesn't strongly rely on syntactically significant white spaces like Python.
  • It has automatic variables. You don't have to use them, and I don't mind them, but it freaks some people out. It does mean you can run cool stuff on the command line like Perl though.
  • It's yet another scripting language, and there will be some inertia to overcome, especially in the staunch work environment.
  • I miss Python's use of named and initialized arguments. This is almost a deal-breaker. Grrr... nothing's perfect it seems. Fortunately, that might change in the future for Ruby, and there are hacks to simulate it now but they are just hacks. I don't like the hacks though.
  • At present there only a relative few books on Ruby in English. Fortunately the first one out is a great one, on par with the Camel book in my opinion.

Currently I'm the only one at my office that uses Ruby. It will probably stay that way due to the inertia problem. But I decided to continue writing and infesting the company research code with it until someday they all seccumb to my will and see the light.

No comments: