Am I missing something with Python not having interfaces?

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Wed May 7 18:12:26 EDT 2008


On 7 mai, 21:19, Daniel Marcel Eichler <onsen-n... at gmx.net> wrote:
> Am Dienstag 06 Mai 2008 16:07:01 schrieb Mike Driscoll:
>
> > If so, then it looks like an Interface is a generic class with method
> > stubs. You can do that with Python just as easily by creating empty
> > methods with just the "pass" keyword.
>
> Well, no. It's a litte different. Interfaces force to implement methods.
> Simple inheritance with method-stubs can't garantee that a specific
> method is reimplementat in a sub-class.

And Java's "Interface" wart can't garantee that a specific method is
*appropriately* implemented. One often sees do-nothing methods in Java
code - useless boilerplate code that's only here to satisfy the
compiler. It's just like Java's "checked exception" mechanism : one
very often sees do-nothing catch-all try/catch blocks in Java - which
is way worse than just letting the exception propagate. I find all
this totally pointless, because there's just no way for a compiler to
check if your code is logically correct.

> Interfaces work at
> compile-time, while method-stubs raise at their first call, so in worst
> case, never.

And then ? If it's never called, why bother implementing it ?

Here again, I don't see the point of compile-time checking.
RuntimeError is a well-known Java exception, so the fact is that Java
forces you into either rigid designs or overly complex workarounds
(best knowns as "design patterns"), without even being able to
garantee anything wrt/ correctness nor even safety. Not that static
typing by itself is necessarily bad - as usual, there's a balance
between somewhat conflicting goals -, but Java's type system
definitivly is (bad).

(snip)
> That's the point. Interfaces garantee that a duck is a duck, an not only
> a chicken that quack.

Who cares if it's a chicken as long as it quacks when you ask her to ?
Now *This* is the whole point of chicken^Mduck typing, isn't it ?-)




More information about the Python-list mailing list