One class per file?

George Boutsioukis gboutsioukis at gmail.com
Mon Sep 29 13:03:00 EDT 2008


On Mon, 29 Sep 2008 06:12:35 -0700, HCB wrote:

> Hello:
> 
> The book "Code Complete" recommends that you put only one class in a
> source file, which seems a bit extreme for me. It seems that many
> classes are small, so that putting several of them in a file seems
> reasonable. I noticed that the decimal.py module in the standard library
> has several classes, all of which of course revolve around the "decimal"
> topic. Perhaps a better rule of thumb is "one idea per file." I checked
> the Python style guide and there seems to be no mention of this topic. I
> know this is an elementary question, but what is the Python way of doing
> this?
> 
> Thanks for your time.
> HCB

That sounds terrible! Imagine having a million source files to edit, 
rename, create, delete each time you make a change. Sure, every Java fan 
can give you a million reasons why the universe will collapse otherwise, 
but this is totally impractical in python. Python's module organization 
and namespaces are more than enough if used reasonably.



More information about the Python-list mailing list