How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python?

David MacQuigg dmq at gain.com
Mon Mar 1 18:31:47 EST 2004


On 24 Feb 2004 14:43:03 -0800, seberino at spawar.navy.mil (Christian
Seberino) wrote:

>How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python?

This question was recently asked in the UserLinux mailing list, in
connection with our selection of Python as the primary scripting
language.  I put together a page of links to other good discussions
and documents http://userlinux.com/cgi-bin/wiki.pl?RubyPython and got
some comments from the Ruby mailing list
http://www.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=9k3k30l67d7j1beguaqg24uc2tmgvtefl1%404ax.com&rnum=1&prev=/groups%3Fq%3Dcompare%2Bruby%2Bpython%2Bgroup:comp.lang.ruby%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D9k3k30l67d7j1beguaqg24uc2tmgvtefl1%25404ax.com%26rnum%3D1

I was considering only the language aspects of the comparison, leaving
aside the number of users, projects, libraries, etc.  I had to sift
through tons of stuff in the mailing lists look for examples of
anything beyond personal preferences for one style over another.  I
came up with two fundamental differences ( see the link above ):  
1) Ruby seems to have a slight advantage in handling complex sequences
of string operations, especially operations that can be stated
concisely as a string of method calls.  I say slight advantage,
because the missing string and list methods could easily be added.
2) Ruby allows you to change the fundamental behavior of core classes
and operations.  If you want string comparisons to be
case-insensitive, for example, you can modify the language to make
that happen.  In Python, you make a subclass of string, and over-ride
the __eq__ method -- not as convenient if what you are trying to do is
change the behavior of a large body of already written code.

Alex Martelli, the source of example 2 above, pointed out that this is
not a deficiency of Python, but a deliberate design choice, making
Python more suitable for production work, but less advantageous as an
experimental language.  In a production environment, we really *don't*
want to make it easy to redefine the behavior of the string class ( as
opposed to over-riding it in your own class ).  We all need to share a
common language.

There is also a frequently stated difference between the use of code
blocks in Ruby and Generators in Python, but I was never able to find
an example where the Python code couldn't be made equivalent to Ruby.
The example on the wiki page above shows that the two differ only in
calling style.  My tenetative conclusion is that there must be some
impressive difference in the way these features work internally, but
to the user it's just a matter of personal preference -- Do you want
to say:
fibUpTo(1000) { |f| print f, " " }
or
for f in fibUpTo(1000): print f,

If there are any Ruby experts here, please take a look at this
generator example.  If there really is some fundametal difference
relevant to the user, I would like to know.

-- Dave




More information about the Python-list mailing list