[Python-Dev] Re: PEP 246 and Protocols (Was: Sneaky 'super' instances)

Raymond Hettinger python@rcn.com
Fri, 13 Jun 2003 00:50:53 -0400


Clark C. Evans

>   The goal of PEP 246 is to create a loose coupling between various
>   framework components to facilitate the 'adapter' pattern as described
>   in the GOF pattern book. 

The adapter pattern is much simpler idea of writing a wrapper and 
possibly using multiple inheritance to link an implementation to a
foreign interface.

PEP 246 is a higher level protocol for seeking and applying
pre-existing wrappers.

Of course you know that, but the summary above tends to 
equate 246 with the GOF adapter pattern.


>   The primary audience of PEP 246 are component/library developres
>   who wish for their components to interoperate between frameworks.

This is why I don't think adapt() should be a builtin.  
adapt.adapt() is not any harder to call than random.random()
or glob.glob().


>   Unless you are writing components and wish for them to work across,
>   say Zope, Twisted, and Webware, using a single code base in a
>   managable manner then you may not understand the PEP.   In particular,
>   PEP 246 will be successful if your average programmer does not
>   even know about adapt!  He simply pluggs component X into framework
>   Y and it works... automagically. 

Yep.  All it takes is one user to contribute code to support a protocol.
My expectation is that the adapter code will (for the most part) be 
contributed by a sophisticated component user rather than the original
supplier of the component.  After all, if the supplier thought the
foreign protocol was important, they would have supplied it in
the first place.  The nice thing about 246 is that the adapter code
can be contributed without altering the original component code
(OCP: open for extension, closed for modification).

I don't see any significant downside to 246.  The code is simple
enough.  It is useful in at least some cases and provides some
support for interoperability.  I don't think it makes writing
adapters any easier -- it does nothing to mitigate the problem
of widely differing protocols with different underlying assumptions.
Getting complete, bug free general purpose adoption will still
remain a hard problem.  Cie le vie.

So, my questions is whether there is any reason not to adopt 246
right away?  AFAICT, there is no competing proposal and nothing
that would be harmed by adoption.  What's all the fuss about?


Raymond Hettinger



#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################