What's better about Ruby than Python?

Alexander Schmolck a.schmolck at gmx.net
Mon Aug 18 17:21:26 CEST 2003


"Brandon J. Van Every" <vanevery at 3DProgrammer.com> writes:

> What's better about Ruby than Python?  I'm sure there's something.  What is
> it?
> 

Since I think this is a reasonable question and I haven't seen to many direct
answer I'll give it a shot.

I recall the following, roughly in order of importance (treat with caution,
it's some time that I looked at Ruby):

0. I it's possible to redefine classes at runtime without going bonkers
   (instances automatically get updated to the new class definitions). This, I
   think is by far python's greatest flaw, amongst other things it greatly
   compromises its interactiveness, which is a key virtue. If someone can
   explain to me how I'm wrong on this and python's behavior really is sane,
   I'll be eternally grateful.

1. syntactic distinction between destructive and nondestructive methods
   (list.sort! vs list.sort)

2. lightweight lambdas (blocks)

3. Generally more OOation (in the style of Smalltalk), if you think that's
   good (doesn't make functional programming easier, for example).  
   The class hierachies are certainly cleaner and, thanks to 'modules' (viz.
   mixins), have less duplication. In python, for example there is no
   reasonable way to find out whether something is a Mapping, or a number and
   classes that should be taxonmically connected aren't and thus reduplicate
   code (or just miss random features; e.g. both `str` and `list` have methods
   that the other one could do with; in ruby this is handled by the
   Enumeration module)

5. continuations, should you so desire.

6. An interesting attempt at an OO case statement.

I should add that 1. and 2. are however inexcusably flawed, especially since
they are really just (badly) adapted from scheme and smalltalk, respectively:

  irb(main):001:0> [1,2].sort
  [1, 2]
  irb(main):002:0> [1,2].sort!
  [1, 2]
  irb(main):003:0> [1].sort
  [1]
  irb(main):004:0> [1].sort!
  nil
  ^^^ !!!

  irb(main):017:0> x = 10
  10
  irb(main):018:0> [1,2,3].reject {|x| x < 2}
  [2, 3]
  irb(main):019:0> x
  3

This together with some other symptoms (what the hell is the point of having
Array.assoc?) gives me the overall impression that Ruby is an uglified
smalltalk, hideously disguised as Perl for mainstream appeal with some random
scheme features on top crafted by someone who doesn't seem to have quite
understood either smalltalk or scheme. OTOH, smalltalk and scheme at least
aren't such bad languages to steal from (even badly) and Ruby has one
worthwhile feature over (standard) smalltalk, mixins (there is BTW, some
interesting work in the squeak community on 'traits').

'as




More information about the Python-list mailing list