[Python-3000] Generic functions vs. OO

Phillip J. Eby pje at telecommunity.com
Thu Nov 23 21:54:23 CET 2006


At 06:14 PM 11/23/2006 -0200, Gustavo Niemeyer wrote:
>(...)
> > A few important points here:
> >
> > 1. A basic interface mechanism is extemely simple to implement, given
> > generic functions
>(...)
>
>All of these points are completely true for interfaces implemented
>without generic functions.

Let's see your implementation.  Zope's interface system fails on at least 
points 3 and 5.  And regarding #1, Zope's implementation of the basic 
features I described is an order of magnitude more complex, even if you 
compare *just* its code that implements adaptation and interface 
inheritance, with *all* of my code plus Guido's generic function 
implementation.

Indeed, even PyProtocols' implementation of similar features is an order of 
magnitude more complex than this.  PyProtocols at least has a kludgy way of 
doing #5, but it fails #3 along with Zope.

My point is that no interface system for Python that I'm aware of can do 
anywhere *near* as much with so little code or complexity.


>In fact, I fail to recognize in your mail a reason why generic
>functions improve the developer's experience at all.  Would you be
>able to expose a concrete case where this system would present
>advantages?

In no particular order:

1. "Recombinant" interfaces

2. Absence of adapter classes for "stateless" adapters

3. No need to adapt for single-operation interfaces (or to define 
interfaces at all in that case)

4. No need to understand interface or adaptation theory to be able to use it

5. Generic functions are easily grasped as a dynamic version of overloading 
as seen in other languages (including C#, Java, C++, etc., where there's no 
built-in notion of "adaptation")



More information about the Python-3000 mailing list