One module per class, bad idea?

Carl Banks pavlovevidence at gmail.com
Tue Dec 12 19:34:13 EST 2006


Carl J. Van Arsdall wrote:
> Carl Banks wrote:
> > Carl J. Van Arsdall wrote:
> >> A module per class makes a lot of sense in some cases, or rather, make
> >> your module your class (look at the singleton pattern).  I actually like
> >> to structure all of my code like this, it helps me keep things organized
> >> and separated.
> >>
> >
> > I don't understand.  Are you saying you organize your code to be a
> > bunch of modules masquerading as singleton classes?  (When I was a
> > young'n, we called that "procedure oriented programming" :)
> >
> Well, when you have a class you want instantiated once and only once
> (i.e. a singleton) you can do it in python really easily vs a langauge
> like C++ (and i'll explain).
[snip]

I understand what you're saying.  It's a good technique to use
sometimes; I've done it myself.  (I've even gone so far as to write
decorator to pass in the module as "self".)  However, I'm quite sure
the OP was talking about real classes, and whether we should limit
ourselves to one real class per module.


[snip]
> Yea, you have a good point.  I don't have a lot of experience with
> packages, but I've also never written anything so large that i've had
> more than 5-10 modules.  I'll spend some time looking into it, thanks!

A ha!

I should note that in my reply I was not thinking about small programs.
 For a small program each class could very well be subsystem unto
itself, so one class per module would be ok.


Carl Banks




More information about the Python-list mailing list