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

Neil Schemenauer nas at arctrix.com
Sun Mar 5 19:48:22 CET 2006


Oleg Broytmann <phd at oper.phd.pp.ru> wrote:

What are disadvantages of a direct .len() instead of .len()?

I can think of a few arguments against getting rid of double underscores in general. First, special methods are a little like keywords in that it would be nice to introduce new ones from time to time without breaking existing code. For example, using getattribute instead of getattribute could have broken existing code.

Another advantage to using getattribute is that it's normally a method that users don't have to know about. Even if there was no problem with breaking existing code it still would be better to use underscores. Someone who doesn't yet know about the magic method could become confused when they use the name for some other purpose.

Finally, there is an advantage to consistent naming. Since some special methods have double underscores, one could argue that they all should have them.

Neil



More information about the Python-Dev mailing list