[Types-sig] Interface PEP

Paul Prescod paulp@ActiveState.com
Wed, 14 Mar 2001 13:06:23 -0800

Michel Pelletier wrote:
> Well, the syntax is a secondary issue, I'm concerned more with the model.
> I think what you are saying is that my proposal specifies that
> specification and implementation must be seperate.  Or maybe you are
> saying what you said, in that case, you lost me.

I think I was saying what I said. :)

Your syntax:

interface ReadableFile:
    def read(size):

>>> print dir(ReadableFile)
[...., implementedBy, ...]

>>> class MyReadFile implements ReadFile:
...     ...

My syntax:

>>> class _ReadableFile:
...     def __implementedby___(self, obj):
...         return hasattr(obj, read)
... ReadFile = _ReadableFile()

>>> class MyReadFile:
...      __implements__=[ReadFile]

> > Mine are basically functional interfaces (in fact
> > they could really be functions instead of classes).
> You lost me there too. ;)

The operative part of my interfaces is the __implementedby__ method.
What you say in a bunch of method declarations, I say in

> > Your interface objects have an implicitly generated implementedBy
> > method. Mine have an explicit method.
> I don't get this either, can you be more explicit about your explicitness,
> also by "your" I assume you mean me?  Above you were referring to me in
> the third person, so I'm lost yet again.

You create objects that don't LOOK like they have an implementedBy
method, but they really do (implicit). I require the creation of an
explicit __implementedby__ method.

The interface syntax version is more compact and readable for
complicated interfaces. The functional version is more flexible. They
will probably work together well as alternate syntaxes.

    Programming the way
    indented it.
       - (originated with Skip Montanaro?)