Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Organisation of python classes and their methods

Reply
Thread Tools

Re: Organisation of python classes and their methods

 
 
Steven D'Aprano
Guest
Posts: n/a
 
      11-03-2012
On Fri, 02 Nov 2012 07:16:09 +0100, Martin Hewitson wrote:

> I'm beginning a large Python project which contains many packages,
> modules and classes. The organisation of those is clear to me.

[...]
> I don't like having source files with
> 100's of lines of code in, let alone 1000's.


Why? Do you do your software development on an iPhone?

Hundreds of lines is nothing, especially if you are including docstrings
and comments in that count. My Python startup file is over 100 lines, and
it is trivial.

100 lines is approximately and a half pages using a 10pt font size
(depending on the font and the platform, of course). In any case, it's
not a lot. If you average two lines of code every comment, blank line or
docstring, 100 lines is only 66 lines of actual code.

To give you an example of what I consider pushing the limit of how much
code should go into a single file, look at the source code to decimal.py.
In Python 3.2, that file is 6249 lines. There are:

- 2880 lines of actual code
- 2070 lines in docstrings, including blanks
- 606 commented lines
- 693 blank lines outside of docstrings

The module includes 20 top-level functions, 18 classes, and 213 methods.
Most of those methods are in just two classes, Context and Decimal, with
76 and 117 methods respectively. So there is an average of 12 lines of
code per function or method.

I wouldn't like to have to deal with a single file twice that size, but
decimal.py is relatively easy to deal with. It's not a trivial module by
any means, but nor is it especially over-complex. The complexity is all
in the computations, not the code layout.

Please understand me -- I'm not saying that you should stuff all your
code into a single module. Code should only be placed into a single
module when the code is related. But in my opinion, you should not split
a logical single unit of code, a module of related code, into separate
files just because it is "too big" until it is at least as large as
decimal.py.


--
Steven
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      11-03-2012
On Sat, 03 Nov 2012 01:06:45 +0000, Steven D'Aprano wrote:

> 100 lines is approximately and a half pages using a 10pt font size
> (depending on the font and the platform, of course).


Crap. I meant approx *one* and a half pages.



--
Steven
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Organisation of python classes and their methods Paul Rubin Python 10 11-03-2012 01:38 AM
Re: Organisation of python classes and their methods Frank Millman Python 0 11-02-2012 09:58 AM
Re: Organisation of python classes and their methods Peter Otten Python 0 11-02-2012 09:17 AM
Re: Organisation of python classes and their methods Robert Kern Python 0 11-02-2012 09:05 AM
Re: Organisation of python classes and their methods Peter Otten Python 0 11-02-2012 08:00 AM



Advertisments