PEP 245

Alex Shindich alex at server01.shindich.com
Sun Apr 1 04:21:05 EDT 2001


I know I am going to get hate mail for this, but I have to get it off my
chest!

I would like to get a few questions answered:

1. What is the point of interfaces without static typing?
All that a proposed definition of an interface guarantees, is that the
concrete classes will implement methods with certain names; no more and no
less. 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. Indeed, there is no requirement that
methods take the same parameters, not to mention that type checking is
impossible? What kind of contract is that? BTW, the return values are not
being checked either.

2. At what point will the compliance with the interface definition be
done, at compile time, or at run time?
If the definition compliance is checked at compile time, then it will
be impossible to add implementation dynamically. Python has always
allowed modifications to the instances at run time. Not that it is always
pretty, but it is possible. Compile time checking would disallow this
technique.

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. In fact, the run time compliance is available already.

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

3. I am just curious... Does any one smell Java here? Not that I have
anything against Java, but I just wonder why Python should turn into
Java. Python is a wonderful, strong, and powerful OO language. It has a
set of its own patterns. Why does it have to support every possible
feature? If someone really misses strong typing and interfaces, maybe you
are trying to use the wrong language for the task? May be, Java is a
better language for this particular set of tasks? Or perhaps, you can
implement the same set of features using Python's real power --
introspection and run time binding.

 -- 
Alex Shindich
mailto:alex at shindich.com
Visit http://www.shindich.com/





More information about the Python-list mailing list