Miscellaneous design and Python use questions

Aahz Maruch aahz at netcom.com
Sat Feb 19 10:52:27 EST 2000


In article <87bt5fgeiq.fsf at travis.aggievilla.org>,
Travis B. Hartwell <travis at travis.aggievilla.org> wrote:
>"Gordon McMillan" <gmcm at hypernet.com> writes:
>>
>> You'll probably be happier if you stop thinking in strict OO terms,
>> and realize that Python is all about interfaces, and interfaces are
>> implicit (no need to inherit from some particular base class). To
>> paraphrase Aahz: loosely couple, and componentize the hell out of
>> everything.
>
>   What exactly do you mean by interfaces here?  I think I understand
>what your paraphrasing meant:  Don't have your classes / modules /
>whatever tied too tightly together (i.e., a good example of information
>hiding) and make everything very indepedent.  Is that right?

That's essentially correct.  It may help if I give you an example:

A while back, I had to write an application in Perl that took a Unix
mailbox and extracted each message in it to do some processing.  When I
converted to using POP3 instead of a mailbox, I uncovered all sorts of
squirrely dependencies despite my careful use of standard libraries and
classes.

Had I written the application in Python (knowing what I now do about how
Python works), it would have been somewhat easier, because I would have
written the two halves of the application twice: in addition to the
"real" version, I would have written a skeleton version of the mailbox
handler and message processer to test the interface to the other half.
This makes it much more likely to produce clean code that separates the
interface boundary correctly.  You actually test this four ways:
skeleton/skeleton, skeleton/real, real/skeleton, real/real.

To put it another way, this is rather similar to (ugh!) the Microsoft
idea of COM objects.  This despite the fact that Python does no real
information hiding.

(Yes, you can do the same thing in Perl, but the style just doesn't seem
to lend itself to thinking that way.)
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Love does not conquer all. Humans are extremely flexible, usually more
flexible than we're willing to admit. But some flexibility comes at a
cost, and sometimes that cost is more than we can bear.



More information about the Python-list mailing list