Why no number methods?

Magnus Lie Hetland mlh at idi.ntnu.no
Mon May 14 06:39:31 EDT 2001


OK, so I've had a look at Ruby. I liked some things
and disliked others... But it made me wonder, why
can't we have methods such as 1.add(2) etc. in
Python? I must admit I haven't looked to hard at the
source code of the interpreter, so I'm approaching
this from a bit of a naïve angle... But if arithmetic
etc. will call suitable methods when objects are
involved, why can't method calls be converted to
arithmetic when numbers are involved? And while
I know we probably can't expect full object-orientedness
before Python 3000, I think it would be really cool
if numbers got the same treatment as lists, strings,
and dicts. (Are there any other types that don't have
methods? OK, Null and Ellipsis don't, but that's
different... :)

And perhaps there could be a UserNumber (possibly
with integer and float subclasses or something)
class, like UserList etc?

The main reason for these musings is that I was
considering an object-oriented approach to teaching
basic Python, but it seems a bit awkward to have
to avoid numbers and arithmetic. (I mean, I can
get quite a long way with lists and strings, but...)

Well, well. Anyone care to explain why this is difficult
or horribly difficult to implement?

Wishing-for-some-consistency-but-not-holding-my-breath'ly yours,

Magnus

--

  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