Why PEP 245??

Matt Butler foo at ix.netcom.com
Wed May 30 04:02:52 EDT 2001


<nanotech at europa.com> wrote in message
news:mailman.991174903.6105.python-list at python.org...
>
> But what enforces the contract?
>

>From what I understood of the PEP you are correct, there is nothing in it
that specifies how the contract would be enforced.  You also mentioned
doc-strings, again you are correct, doc-strings can be used as a primitve
way to describe interfaces.  I believe that the folks at Digital Creations
currently use doc-strings for exactly that purpose.  I think though that
they have found this method wanting for several reasons (The author of the
PEP works at Digital Creations I believe).  Here are some that I can think
of:

    No standard way to disambiguate documentation of a class's interface
from documentation about how blue the sky is, or what year it is, etc...

    Normal end-user documentation now obfuscated by special tokens intended
to be read by other classes, not humans.

    People's desire to use inheritance (the mix-ins you mentioned) to
express interface.  In my mind there is nothing unfashionable about
inheritance, it's simply a different relationship than the one expressed by
two classes having a common interface.  My elephant class may derive from my
mammal class, but that has nothing to do with whether or not I have Elephant
implement the turbo-boostable interface.

    Sometimes I code in Java, I can definitely say that the use of
interfaces in Java has saved me time.  There have been several occasions
where I was able to see that a class implemented a well-understood interface
and then not had to refer to the documentation anymore... I knew how it
worked.

Butler






More information about the Python-list mailing list