Python style questions

Aahz Maruch aahz at panix.com
Fri Mar 16 11:10:41 EST 2001


In article <98tb91$9t9$1 at saltmine.radix.net>,
Cary O'Brien <cobrien at Radix.Net> wrote:
>
>1. I have a class that handles communications with a remote service.
>   It is fairly complex, having to deal with timeouts and retransmits
>   and the like.  The class definition is getting bigger than I'd like.
>   Should I
>
>    a. Live with it
>    b. Factor into mix-in classes
>    c. Define some methods outside of the class definition.
>    d. ???

Separate out the data handling from the communication.  I'd suggest
creating a separate class that handles the low-level communication and
putting an instance of it into your main class.

>2. One thing I've done is to define classes used only by another class
>   inside that class.  For example, if a class A needs to keep track of a
>   bunch of "things", then the class definition for the "things" is inside
>   of the class definition of A.  This is
>
>   a. SOP
>   b. Brilliant
>   c. Idiotic

Depends.  I'm not fond of that trick, though.  It makes more sense to
divide this stuff into modules.

>3. I really miss not having a "switch" or "case" statement.  Sniff.

Use a dictionary.
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

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

Three sins: BJ, B&J, B&J



More information about the Python-list mailing list