[Python-3000] Special methods and interface-based type system

Jim Jewett jimjjewett at gmail.com
Sun Nov 26 01:03:16 CET 2006


On 11/22/06, Bill Janssen <janssen at parc.com> wrote:
> > yeah, namespaces are such a useless thing.  let's put everything in one
> > big flat namespace, so we don't have to wonder where things are.

> Pardon me?  That's what we've got now, isn't it?  That's why we have
> to do that ugly and hard-to-explain name mangling for "special"
> methods.

Not quite.

The documentation (http://docs.python.org/ref/id-classes.html) states
that __special__ methods are reserved to the language.  This isn't
strictly enforced, but it does add a second namespace.

There isn't usually any need for a third namespace, unless you are
using another huge framework, such as Zope or Peak.  If so, the
frameworks have their own conventions.  I have no opinion on whether
their conventions happen to be good, safe from false alarms, or even
frequently used; I am stating only that the frameworks themselves are
responsible for carving out their pseudo-namespaces.

That said, I think the situation would change (for the worse) if we
started to see heavy use of generic functions or interfaces.

These should not use the __special__ convention (they aren't part of
the system, and won't all even be widespread).

Using a designated name in the main namespace will lead to clashes.
(Not every "next" attribute is an iterator-related function).

I had thought that you (Bill), (along with PJE) were assuming that the
generic function or interface itself would serve to distinguish the
namespace.  Instead of

    class A(object):
        def magic_meth_foo(self, ...):

I would write

    class A(object):
        defop foo.magic_meth(self, ...)

This does work, but ... code gets just a little bit longer, with the
extra going to dots and boilerplate.  The boilerplate won't hide the
way "__" does.  It probably shouldn't always hide, since it won't even
be boilerplate in some cases.  But it will be boilerplate so often
that readers will start to skim, even when they shouldn't.

In the end, that extra almost-boilerplate strikes me as a very high
price to pay, and I'm not sure it can be avoided unless Interfaces and
Generic Functions stay relatively rare.

-jJ


More information about the Python-3000 mailing list