What's TOTALLY COMPELLING about Ruby over Python?

John Roth newsgroups at jhrothjr.com
Mon Aug 18 16:22:01 EDT 2003


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3F41208F.40021A68 at engcorp.com...
> Daniel Dittmar wrote:
> >
> > Brandon J. Van Every wrote:
> > > What's ***TOTALLY COMPELLING*** about Ruby over Python?  What makes
you jump
> > > up in your chair and scream "Wow!  Ruby has *that*?  That is SO
FRICKIN'
> > > COOL!!!  ***MAN*** that would save me a buttload of work and make my
life
> > > sooooo much easier!"
> >
> > Code blocks, although I'd rather go to the source and steal them from
> > Smalltalk.
>
> What is it about code blocks that would let "save *me* a buttload of work
> and make *my* life sooooo much easier"?

It's not so much code blocks. It's that Ruby's syntax  gives you one code
block for
free in every method call. And the Ruby library is organized so that the
facility
is useful, which Python's isn't (or at least, it isn't as useful.)

All of the Ruby collections implement a .each method, which is essentially
a version of the Visitor pattern. If I want to do something to every element
in a list or a dict (or any kind of collection,) all I have to do is say
something
like (using Python syntax):

collectObj.each(<method name>)

In Python, that's either a lambda (which restricts what you can do with it,)
or a named function (which is overkill a huge amount of the time.) And you
have to worry about distinctions between functions and methods. In other
words, it's a mess compared to Ruby.

Now, you can say: "We've got that with map()." Well, we've got it when
your inputs are either lists (or implement the correct protocol) but the
result is a list, it's not an internal modification to the object's state.

You can also say: we can do that with for. Well, duh. For is a
statement, not a method call.

To continue on this vein, Ruby directly implements Visitor, Observer,
Delegate and Singleton. I don't particularly like the way it does some
of them, but Python can't claim any one of the four!

Granted, you can do a clean singleton using new style classes and the
__new__() method, but (as of 2.3) it's not anywhere in the core
documentation
that I could find. Observer is simply a couple of classes. Visitor I've
discussed above, and I'll leave Delegate for the reader.

> If one can't answer that, one shouldn't expect to be able to answer
whatever
> the heck it is Brandon has in mind (which is clearly not much), since
> only he has any idea what it is he wants, and we're not even sure about
that...

It might be better to simply take the question at face value, rather than
slanging Brandon. I don't find the personalities to add anything of value
to the conversation.

John Roth
>
> -Peter






More information about the Python-list mailing list