Why not 3.__class__ ?

James_Althoff at i2.com James_Althoff at i2.com
Wed Oct 10 22:15:30 CEST 2001

Magnus Lie Hetlands wrote:
>Well... I'm not sure it's unfortunate. For a beginner, it might be easier
>translate the above into something understandable ("for each value of the
>index variable i in the range up to 100, execute the following block")
>it would be for the Ruby version ("call the times method of the number 100
>with an unnamed code block, which will then be executed with the numbers
>up to 100 supplied for the parameter i").
>The Ruby version may be nice, but seems unnecessary to me, as long as you
>actually have a looping construct in the language. (And if you haven't,
>methods like .times must have them internally anyway...)

The difference between "nice" and "unnecessary" is that in Ruby and
Smalltalk you can have debates about whether to name your method "times" or
"timesRepeat" instead of -- as we see constantly in Python -- having
endless debates about how feasible it is or isn't to add new syntactic
sugar and what sugar would be the most "Pythonic" to many users and the
least offensive to others.  Until you have the chance to use unnamed,
in-place code blocks as arguments to methods it can be hard to appreciate
how *easy* it then becomes to extend a language without having to add new
syntax (and keywords).

>I do, however, think it would be nice to have some syntactic sugar for the
>range function, e.g.:
>  for i in 1..10: foo()

Certainly it is hard to argue that having to call a function like range()
-- and having two essentially equivalent functions around for that purpose
-- is something that is *intuitive* for beginners.

>But I guess that'll never happen. <sigh> :)
>(And, no, I don't like names like "xrange" either.)


More information about the Python-list mailing list