PEP 245

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sun Apr 1 09:26:49 EDT 2001


Sun, 1 Apr 2001 00:21:05 -0800 (PST), Alex Shindich <alex at server01.shindich.com> pisze:

> 1. What is the point of interfaces without static typing?

To formalize requirements about objects.

To get better error messages early, instead of cryptic errors raised
deep where the object was finally actually used.

> There is no guarantee that method doSomething declared in the
> interface has anything in common with the method doSomething declared
> in the concrete implementation class.

It cannot be guaranteed in general in any framework. But an interface
implies some properties of its methods and objects should be declared
as conforming to an interface only if their methods really have an
appropriate meaning.

> 2. At what point will the compliance with the interface definition be
> done, at compile time, or at run time?

At runtime. Well, theoretically one could try to write a static
analyser, but it would be hard for Python.

> If the compliance is checked at run time, then interface checking is
> as good as as simply assuming that the method is implemented. Today,
> I can compile code like "f.doSomething ()" without f actually
> implementing doSomething. At run time I would get an AttributeError
> thrown into my face.

You may get the error too late or with unhelpful error message, and
you won't get the error if the object happens to have a method of
the given name but the method means a completely different thing.
And you don't have a hint what objects a method expects nor what
objects it returns, besides some informal explanation in docs.

> Also, will it be possible to instantiate classes that do not
> implement all the interface methods?

All methods of which interface?

> 3. I am just curious... Does any one smell Java here?

I would prefer to discuss features themselves than to draw conclusions
from similarities to other languages, especially languages we don't like.
Comparisons to other languages can be helpful in finding good and bad
sides of these features, but I have nothing against a similarity itself.

Well, there were other proposals discussed on types-sig at python.org
that I liked more than PEP 245. They happen to be less Java-like
(e.g. no declaration of interface conformance during class definition).

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list