Guido van Rossum wrote:
> On 11/21/06, Phillip J. Eby <[EMAIL PROTECTED]> wrote:
> [...]
>> That's because some generic functions use if-isinstance checks (bad), while
>> others use custom __special__ methods (not bad, but not great), registries
>> (good), adaptation (okay), or generic function libraries.
>
> __special__ methods are great for many purposes because they are well
> understood. Registries are mostly good when there's a need for an
> independent third party to add an ability; IMO this isn't as common in
> most places as you seem to think.
Another effect of __special__ methods is that they divide the class
namespace into two parts: The __special__ names are those that have to
be implemented to support core Python interfaces, and the methods
without underscores are those that implement the "main aspect" of the
class. However there might be other aspects worth supporting (fancy
repr, pickling, GUI output, etc.). The methods needed for that support
either have to share the special namespace or the main namespace.
In Java there are interfaces, but there's only one namespace in which
support for an interface can be implemented, so method names have to be
fairly long to minimize collisions.
With generic functions that problem goes away. It's no longer the name
of the method that links the implementation to the protocol, but an
explicit registration of the implementing function.
> [...]
Servus,
Walter
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com