Cool things about Ruby on the way out of Python?

John Farrell jfarrell at mincom.com
Mon Feb 21 22:42:38 EST 2000


After a debate on this list about claims made in this paper:

Ruby: a new language
http://www-4.ibm.com/software/developer/library/ruby.html

I read the paper to learn what the fuss about Ruby was about.
Ruby is a pretty neat language designed like an OO form of Perl. If I had
to summarise it in one sentence, I would say "OO Perl without so much line
noise, and these cool things called iterators". One of the big things Ruby
does is allows you to pass around blocks of code as parameters. In Python,
they are equivalent to lambda expressions, except that in Ruby the body of
the lambda can (directly) contain statements.

In Python you would write:

for x in [1, 2, 3]:
    print x

In Ruby you would write:

[1, 2, 3].each do |x|
    print x
end

A more direct translation would be:

map (lambda x: print x, [1, 2, 3]) # not legal Python, I know

Effectively everything you can iterate over in Ruby has to implement
this 'each' functionality, then you can pass code into it. (BTW, I really
dislike the magic syntax to invoke the code in Ruby, but that's not
the point of this thread.)

Now, the good things about the Python way are:

 * easy to understand
 * no sucky Perl-like syntax

The good things about the Ruby way are:

 * because you can implement each yourself, you can make it mean different
   things for all the types of objects you iterate over.
 * you can put statements inside lambdas

IMHO, if we could get around the syntax problems, map/each and lambda
could be used to write beautiful programs. I think the reason that
lambda doesn't really work in Python is because it can only return
values, and hence doesn't do what you might want it to all the time.
Map also doesn't work because it is such a fundamental concept that it
needs to be syntax (hence list comprehensions), and once you make it
into a function it's harder to see what it does.

Ruby looks cute. If I was a Perl user I might be tempted to go to it.
In the mean time, I will stick with Python, and pine for the long days
by the fjords spent writing Miranda.

John
-- 
Dr John Farrell - Research Architect - Mincom Limited

I don't suffer from stress.  I am a carrier.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d- s++:+ a C+++ U+ P-- L E--- W++ N+(-) o+ !K w---(+) !O !M !V PS+ PE Y?
PGP t--- !5 !X R(+) tv- b++ DI++ D G e++++ h---- r+++ y++++(*)
------END GEEK CODE BLOCK------
This transmission is for the intended addressee only and is confidential
information. If you have received this transmission in error, please delete
it and notify the sender. The contents of this E-mail are the opinion of the
writer only and are not endorsed by Mincom Limited unless expressly stated
otherwise.




More information about the Python-list mailing list