Why does Python mix OO concepts and non OO concepts for operation s on basic types?

Michael P. Soulier msoulier at mcss.mcmaster.ca_.nospam
Wed May 22 18:59:18 EDT 2002


On 23 May 2002 00:01:17 +0200, Chris Liechti <cliechti at gmx.net> wrote:
>  
> think abbout it as an operator. its is written in function syntax because 
> +-*/% etc are aleady used.
> 
> it has some advantages and it isn't "inconsistent" at all. i think you 
> do prefer to write 
>>>> 1 + 2
> instead of
>>>> 1 .__add__(2)
> don't you?
> (with or without underlines. apropos, "range(3).__len__()" works ;-)

    Actually, one of the few things I like about Ruby is that all objects in
Ruby do have methods, and thus to add two numbers...

    2 + 4
    2.+(4)

    are equivalent. 

    Python _does_ seem mildly inconsistent in this regard. Giving strings
methods helped a bit, but tuples still have none, and neither do numbers.

>>> dir(())
[]
>>> dir(2)
[]

    IMHO, they should all be objects with methods and a class, such that they
may be subclassed. 

    Mike

-- 
Michael P. Soulier <msoulier at storm.ca>, GnuPG pub key: 5BC8BE08
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix



More information about the Python-list mailing list