Are there 'Interfaces' in Python??

Quinn Dunkan quinn at seniti.ugcs.caltech.edu
Mon Oct 1 15:04:53 EDT 2001


On 29 Sep 2001 01:19:24 -0700, Titus Brown <t at chabry.caltech.edu> wrote:
>Interfaces (or better, signatures, as you describe below) seem to
>have the advantage of being up-front about checking requirements,
>rather than being a bit lacksadaisical about when requirements are
>checked.

My feeling is that there are two python "styles" which address this:

Try and see (i.e. catch the AttributeError, this is what you called "hacked"
above).  Also called "better to ask forgiveness".

Provide good documentation.  Docstrings are good for this.  Of course, many
want to know why you should document in english and make humans read it rather
than documenting in the programming language (via interfaces) and make the
computer read it.  My answer is that interfaces add complexity and english
(well, natural language (or even unnatural language, like Dutch)) often works
just fine for this.  If your interface requirements are so complicated that
it's hard to express and follow in english (or it's hard to know what to
document), maybe your code needs some work.  Of course, there are situations
that refute this answer, which is why people still want interfaces.

Based on the above, rfc822 should have either 1- included "if the file
supports seek() it must support tell() (or was it the other way around?)" in
the documentation, 2- checked for the existence of both seek() and tell()
before it started using them, or 3- not used seek() and tell() at all, if
possible without complexity.

In this instance, I'd favor 2.  If you're feeling like doing a good deed, you
could fix rfc822 and submit a patch :)



Someone must have unplugged Alex or deleted his state pickle... both
"interfaces" and "signature-oriented polymorphism" have come up and he's
nowhere to be seen.



More information about the Python-list mailing list