Why no number methods?

Costas Menico costas at meezon.com
Mon May 14 09:02:37 EDT 2001


If you are really going to teach pure OOP then you want to look at the
king of OOP; Smalltalk (http://www.object-arts.com or
http://www.squeak.org) or comp.lang.smalltalk

But even in Smalltalk an addition looks like 

3 + 4.

Smalltalk sends all mesages and operands from left to right. But in
this case (the + is called a binary message as opposed to keywords or
unary) it is actually sending a + to the object 3 with an argument of
a the object 4.

However you can also do

3 factorial + 4. 

In the new imaginary python you would have to say 3.factorial() + 4.
This would mean that the factorial() method would be understood by all
numbers. Which means all numbers (Floats and Ints and Complex) are
class instances. Numbers in Python don't have classes and are not
extensible. If they did it could be done, barring any syntactical
issues (e.g. 3.14.sin() ) that you would have to deal with.

Costas



More information about the Python-list mailing list