Why NOT only one class per file?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Apr 5 04:32:37 EDT 2007


Sherm Pendley a écrit :
> Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> writes:
> 
>> Chris Lasher a écrit :
>>
>>> so I thought I'd ask here to
>>> see why the Python idiom is the way it is: why should we NOT be
>>> placing classes in their own separate files?
>> Because it just sucks.
> 
> ...
> 
>> Just ask him why Java insists on 'one-(public)-class-per-file', and
>> why it's considered good form in C++. I mean, the real *technical*
>> reasons...
> 
> Yeah, as if "because it just sucks" is a technical reason. :-)

It doesn't pretend to be one !-)

> It's a stylistic thing, nothing more. 

A bit more than just 'stylistic' IMHO. It's a matter of convenience. 
Having to manage hundreds of files each with a dozen lines of code is a 
PITA. Having to retype the same import statements in hundreds of files 
is a PITA - and a good way to waste time and forget something when one 
has to fix these import statements (yes, even with the appropriate 
tediting tools). I wouldn't call such considerations "nothing more than 
stylistic".

> There's no technical basis for it,

No, but there's no technical reason for putting each class in a separate 
file.

> just personal preference.

True, I prefer to avoid boilerplate proliferation, switching-file-dance, 
and maintenance nightmares.



More information about the Python-list mailing list