Why NOT only one class per file?

Jarek Zgoda jzgoda at o2.usun.pl
Wed Apr 4 17:33:14 EDT 2007


Chris Lasher napisał(a):

> A friend of mine with a programming background in Java and Perl places
> each class in its own separate file in . I informed him that keeping
> all related classes together in a single file is more in the Python
> idiom than one file per class. He asked why, and frankly, his valid
> question has me flummoxed.
> 
> I tried to rationalize this Python idiom by claiming a file--a single
> module--makes for a great container of code which is logically tied
> together, such as a class and its subclasses. He posited that
> directories (packages) can tie the files together just as well, and by
> having the classes as separate files, he can "diff" them to see how
> they differ, something he wouldn't be able to do with the code all in
> one file.

I'd not try to rationalize it, it's just natural. The requirement to
have only one public class per module needs rationalization (other than
limitation of compiler), not the freedom to have as much of classes in
module as is needed by program's architecure.

-- 
Jarek Zgoda
http://jpa.berlios.de/



More information about the Python-list mailing list