I did Python back in 2003-5, when I was a Plone/Zope consultant. Then
in 2006 I started picking up Ruby. I've never looked back. I think
different people feel more comfortable with different programming
languages and cultures, but for me, Ruby feels a lot better than Python.
I personally think that compared to Ruby, Python is the reliable
workhorse that happens also to be a bit staid and bland. Ruby is a lot
more fun. It's a prettier looking language, and can be made to do a lot
of fun and funky things that keep wowing its practitioners. I've heard
Python people attack Ruby for being too dangerous, saying that it's too
easy to re-open classes and do wild and irresponsible stuff like that.
But that's part of what makes Ruby feel like an action adventure comedy
romance to me. Python, by contrast, is more like Ikea furniture: it's
pleasant, comfortable, and reliable -- but it will never surprise you and take your breath away.
The two best things about Ruby, from my perspective, are the two things
that distinguish it sharply from Python. First, Ruby is influenced a lot
by Perl. Python seems to take pride in being the anti-Perl. But the
stuff Ruby borrowed from Perl is of great practical value. Take regular
expressions, for example. In Ruby, you can write regular expressions
naturally, e.g. if mystring =~ /^\s+hello word!/ ...
. In Python, not
so much, because Python is so anal about making everything follow a
uniformly predictable syntax. In Ruby, you can get STDIN immediately
with input = STDIN.read
. In Python, you have to import sys
and then
sys.stdin.read()
. These are but two examples where Python's effort to
distance itself from Perl and be so predictably regular is trumped by
Ruby's willingness to do what feels right in each case.
The other thing that distinguishes Ruby from Python is that Ruby is much
closer to Lisp whereas Python is pretty much an imperative programming
language. I think this is a big plus in Ruby's favor.
There many Lisp-like features of Ruby that make it possible to do more
with less code in Ruby than in Python. For example, every statement and
control structure in Ruby returns a value: you can get away in Ruby with
never using the return
statement. Even if
statements evaluate to a
value, so you can write stuff like this
result = if output == 'hello'
[some code here]
"world"
else
[some other code here]
"there"
end
In Python you would have to write
if output == "hello":
[some code here]
result = "world"
else:
[some other code here]
result = "there"
Python makes you type result =
twice. That's not very DRY (Don't
Repeat Yourself). There are a lot of instances like this where Ruby will
be more DRY than Python because of its Lisp-like qualities. Matz, the
creator of Ruby, came from a Lisp background.
Some people say that Ruby also kicks Python's ass in metaprogramming
(aka dynamic programming). Python people respond either by saying that
metaprogramming is too dangerous, or by saying that theoretically, you
can accomplish all the metaprogramming stuff Ruby can in Python, just
differently. But one thing everyone does agree on is that metaprogramming is far less
common in Python than in Ruby. And that's too bad, because metaprogramming is
a trip.
I think it's probably true that at the end of the day Ruby and Python
can both get the job done. Compared to C and Java, Ruby and Python are
pretty much the same thing. They are expressive, productive, high-level
languages.
So it boils down to your personality.
Do you like things to be predictable, regular, and safe? Do you like the
imperative style of programming? Do you want to maybe work someday for
Google? Do you think that Perl is a chaotic spawn of hell? Stick with
Python.
Do you take great pleasure in finding the absolutely most concise way to
accomplish some programming result? Do you get bored by regularity and
uniformity? Do you like to have the freedom to write code in a style
that is all your own, and have a lot of space to come up with your own
cool tricks? Do you feel more of an affinity for Lisp than for C? Do
you feel great admiration for Perl's epoch-making contribution to software
programming, but only wish that it could be just a little less cryptic
and ugly? Do you think of code like other people think of poetry? Try Ruby.