Wed, 07 Jun 2006
Ruby vs. Python (vs. Perl) (vs. Lisp)
I've recently been playing with Ruby, and I think I've finally found a replacement for my various uses of Perl. For a while now, I've been using one of two languages for my at-home programming: Common Lisp for the more complex or interesting tasks; and Perl for the simpler tasks, standalone programs, and one-line text processing.
I've long had a love/hate relationship with Perl. On the one hand, its
DWIM approach to things make it easy to do simple things, especially
one-off text munging.
perl -pe '<stuff>' has long been my friend. It
also has CPAN going for it; many of my problems have been solved with a
CPAN module and a little glue code. On the other hand, Perl tends towards
extreme ugliness, especially when the code starts to get complicated.
I've never liked the OO interface for Perl, for example; not only does it
feel very obviously bolted on to an existing infrastructure, it didn't
even get the sharp, pointy edges sanded down when they did it.
Thus it was that I was impressed with Python when I first met it. It
felt like a language designed with OO from the bottom up. (But it wasn't;
the addition of OO stuff had just been done in a much better way than
Perl's.) It had nice data introspection. It had functions as first-class
objects (so they got the benefit of introspection, as well as the other
benefits of first-classness). I figured I could live with the
whitespace-as-syntax wart. As I got to know it more, Python started
falling down in a few places. For one thing, Guido van Rossum apparently
doesn't like functional programming. Python has some functional
programming constructs, like map and filter, but Guido keeps threatening
to remove them. There's no good way to create anonymous functions,
lambda is only useful for relatively trivial purposes.
Python is also not terribly useful from the command line, largely because
of the whitespace-as-syntax thing. Again, it works for some trivial
cases, but is not general purpose enough.
So it was that I resisted bothering with Ruby for a while. "Oh," I said, "It's just another fad, like Python." But I kept hearing good things about it, even apart from all the buzz that Ruby on Rails has generated. So I finally resolved to poke at it a bit, and I'm pretty impressed. It's a much cleaner language than Perl, but it's better at functional and command-line usage than Python. It's enough to make me want to switch to Ruby for all my non-Lisp needs.
There are some things that feel like they might bother me, though. While Ruby not only supports anonymous functions but uses anonymous-function-like blocks all over the place, functions in Ruby are not first class objects, which means that you can't quite sling them around as easily as data. The use of special characters to determine variable scope (globals, class variables, instance variables, etc.) seems a bit weird to me, but at least it's not as bad as Perl's variable special characters.
Basically, Python has too much insistence on doing things its own particular, sometimes convoluted way. Ruby stole all the useful things from Perl while otherwise maintaining a very clean language that doesn't spit on my Lisp-influenced thinking.