Why not 3.__class__ ?

Magnus Lie Hetland mlh at idi.ntnu.no
Wed Oct 10 20:44:15 CEST 2001

<James_Althoff at i2.com> wrote in message
news:mailman.1002735730.12645.python-list at python.org...
> Yukihiro Matsumoto wrote:
> <snip>
> >I'm not sure Python needs something like 3.method.  Python's
> >integers have far fewer methods than Ruby (because it uses
> >functional style).  And it doesn't have idioms like
> >
> >  100.times {|i|
> >    puts i
> >  }
> >
> >So (3).method is enough for Python.
> Agreed.  Invoking methods on literals (like integers) is quite nice when
> you have methods that take unnamed, in-place, code blocks as arguments as
> is possible in Ruby (example above) and Smalltalk.
> Obviates the need for unfortunate idioms like "for i in range(100):" -- or
> should we make that "xrange"? ;-).

Well... I'm not sure it's unfortunate. For a beginner, it might be easier to
translate the above into something understandable ("for each value of the
index variable i in the range up to 100, execute the following block") than
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, then
methods like .times must have them internally anyway...)

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()

But I guess that'll never happen. <sigh> :)

(And, no, I don't like names like "xrange" either.)

> Jim


  Magnus Lie Hetland         http://www.hetland.org

 "Reality is that which, when you stop believing in
  it, doesn't go away."           -- Philip K. Dick

More information about the Python-list mailing list