One module per class, bad idea?

Kent Johnson kent at kentsjohnson.com
Fri Dec 22 10:56:05 EST 2006


Carl Banks wrote:
> Now, I think this is the best way to use modules, but you don't need to
> use modules to do get higher-level organization; you could use packages
> instead.  It's a pain if you're working on two different classes in the
> same system you have to keep switching files; but I guess some people
> prefer to switch files rather than to scroll for some reason.

That would be me. I strongly prefer to switch files rather than scroll. 
I use an editor that makes it easy to switch files. For me it is much 
easier to switch between files than to scroll between two parts of a 
file, and I don't lose my place when I switch back. I like to be able to 
see things side by side.

So I do tend to put classes in separate modules. Not always - when two 
or more classes are closely related or a class has one or more helper 
classes they may share a module - but in general my major classes are 
each to a module.

It does make the imports look funny - I tend to give the module the same 
name as the class, Java style, so I have
from foo.bar.MyClass import MyClass
but that is a minor point IMO.

Kent



More information about the Python-list mailing list