Re: Organisation of python classes and their methods

Discussion in 'Python' started by Steven D'Aprano, Nov 3, 2012.

  1. 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
    Steven D'Aprano, Nov 3, 2012
    #1
    1. Advertising

  2. 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
    Steven D'Aprano, Nov 3, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Rubin
    Replies:
    10
    Views:
    265
    Steven D'Aprano
    Nov 3, 2012
  2. Peter Otten
    Replies:
    0
    Views:
    180
    Peter Otten
    Nov 2, 2012
  3. Robert Kern
    Replies:
    0
    Views:
    216
    Robert Kern
    Nov 2, 2012
  4. Peter Otten
    Replies:
    0
    Views:
    228
    Peter Otten
    Nov 2, 2012
  5. Frank Millman
    Replies:
    0
    Views:
    248
    Frank Millman
    Nov 2, 2012
Loading...

Share This Page