About one class/function per module

Diez B. Roggisch deets at nospam.web.de
Mon Nov 2 14:27:40 CET 2009

Peng Yu wrote:

> On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers
> <bruno.42.desthuilliers at websiteburo.invalid> wrote:
>> Peng Yu a écrit :
>> (snip)
>>> I prefer organized my code one class/function per file (i.e per module
>>> in python). I know the majority of programmers don't use this
>>> approach. Therefore, I'm wondering what its disadvantage is.
>> Hmmm... As far as I'm concerned, you already answered your own question:
>> "the majority of programmers don't use this approach".
>> Now, for a much more practical answer:
>> 1/ having to handle thousands of files for even a simple project is a
>> king-size PITA for the maintainer.
>> 2/ having to load thousands of modules will add quite a lot of overhead
>> when actually running the code.
>> 3/ as a result, the poor guy that will end up maintaining your code will
>> positively hate you. Beware : this poor guy might as well be you.
> I still don't understand why it is a nightmare to maintain the code.
> For my C++ project, so far so good.
> I can easily change filenames (that is class name or function name), I
> can easily find them, I can easily move things around, all with just
> the corresponding script command. I can navigate to the definition of
> class and function by vim + ctags, I can see example code that calls
> the class/function. Whenever I suspect there is a bug, I can easily go
> to the right level of class/function in the directory hierarchy to
> write a test case to trace down the bug without having to use gdb.
> Would you please let me why it is a nightmare?

My current project has about 1300 source-files (luckily *not* laid out in
your preferred way), which contain 1900 function-definitions (most probably
even more so) and about 1700 classes. So your "approach" more than doubles
the number of files to juggle around - in my head, in my editor, and so on.

Not to speak about the inability to rename a function or class just in
source-code. No, I'd also have to rename the file, causing all kinds of
extra issues when using version-control-systems (which of course I do).

It's simply a braindead idea. Get over it. Get rid of your "useful" scripts.
Start learning a decent editor (emacs is mine) which allows you to deal
with all of your perceived "problems" without making even small projects a
nightmare of a bazillion files.

Again: *program* in python, don't fantasize about something that's not
there, and writing shoehorning-scripts. That's just an excuse to be


More information about the Python-list mailing list