Does Python support interfaces?
Eric Hopper
hopper at omnifarious.mn.org
Tue Jul 18 20:14:07 EDT 2000
In article <8l2i4101pon at news2.newsguy.com>, "Alex Martelli"
<alex at magenta.com> wrote:
>
> Yep, it is exactly what C++ does in its templates. Of course, they're
> resolved at compile-time in C++, but then Python is not about
> compile-time vs run-time distinctions, is it?
I know. It's what I dislike about templates in C++. An occasional
project of mine is wrapping all of the silly STL things in a properly
defined interface hierarchy to both avoid all that extra code being
generated for new types, and so STL is, IMHO, conceptually cleaner.
> See Austern's excellent book on Generic Programming (and, also, on the
> STL) about the GP metaconstruct he calls "concept", and how and why it's
> not modeled by inheritance even in C++. The compiler cannot diagnose
> many kind of concept-violations anyway (they're deeply semantic, e.g.,
> the concept that a certain function imposes a strict weak ordering) so
> little is really gained by compile-time checks.
Now, this is a worthwhile suggestion. Thanks! Maybe (s)he'll be able to
change my mind. :-)
I agree about the concept violation problem. I mostly think that
interfaces make a nice form of enforced documentation, and reduce code
bloat in languages with static type checking.
--
Eric Hopper <hopper at omnifarious.mn.org>
http://www.omnifarious.org/~hopper
More information about the Python-list
mailing list