New to Python: my impression v. Perl/Ruby

Francis Hwang sera at fhwang.net
Wed Jan 21 15:31:19 EST 2004


Ville Vainio <ville.spamstermeister.vainio at thisisspamprotectiontut.finland> wrote in message news:<du71xpue3rm.fsf at mozart.cc.tut.fi>...

>     Phil> 10.times do something end
> 
>     Phil> is somehow so clear.  It's almost zenlike.
> 
> It's cute and fun to write, but less cute for people who have to read
> lots of such code in short time. I have a soft spot for such style
> also; I kinda like Python's "\n".join(["foo","bar"]), even if most
> seem to consider it a wart for readability reasons.

A lot of this has to do with how you conceptualize objects. In some
languages objects are big and heavyweight. So the few things that get
to be called Objects are blessed with special powers, and the lowly
primitive values are supposed to look up to them with admiration and
reverence.

In other languages everything can be an object, which means that you
have to think of the "object" idea differently. In Ruby integers are
objects, but there's a lot of syntactic sugar to make that happen.
After all,

  10.times do something end

is basically just fancy talk for

  for (i = 0; i < 10; i++ ) { something }

or whatever you think should be more explicit. This method might break
your conceptual model of what an object is, depending on which model
you like.

Personally, I love the Fixnum#times method, since it means I never
make fence-post errors anymore. More time for interesting problems,
less time spent on tediously stepping through code one iteration at a
time. And if my conceptual model is getting in the way of my ability
to write error-free code, then it's the conceptual model that has to
change.

Besides, once a language is Turing-complete, everything else is
syntactic sugar. So you might as well get the best syntactic sugar you
can get ...

Francis



More information about the Python-list mailing list