[Python-Dev] .len() instead of __len__() (was: iterator API in Py3.0)

Oleg Broytmann phd at mail2.phd.pp.ru
Sun Mar 5 15:44:17 CET 2006


On Sat, Mar 04, 2006 at 04:31:26PM -0500, Phillip J. Eby wrote:
> I'm not sure that "more object-oriented" should be equated with "good" in 
> this context, or indeed any context. :)

   I am sure it is.

> A function is no more or less 
> polymorphic than a method in any case, especially if the function is 
> normally delegating to a slot or special method in any case.

   Advantages of a method over a function:

-- a method is a more natural way to query or manipulate objects;
-- a direct method call is faster than two-level call (len() => .__len__());
-- unnecessary cluttering of builtin namespace; the namespace should(1)
   contains only really global functions (__import__(), eval(), etc.)

   What are the advantages of a function over a method? What are
disadvantages of a direct .len() instead of .__len__()?


(1) I am a perfectionist and I partially disagree with "practicality beats
purity"; I would really love a small uncluttered builtin namespace in

     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

More information about the Python-Dev mailing list