Code density

Discussion in 'Python' started by j_mckitrick, Jun 13, 2004.

  1. j_mckitrick

    j_mckitrick Guest

    When I was reading the PEP for code, Guido suggests using blank lines
    'sparingly.' Yet, in most of the 'professional' code(1) I've seen,
    there are often HUGE amounts of whitespace, extra blank lines, and so
    on. Is this the norm?

    Has python gravitated toward more whitespace in general?

    jonathon

    (1) Zope, RocksClusters, anaconda, and others
    j_mckitrick, Jun 13, 2004
    #1
    1. Advertising

  2. j_mckitrick wrote:
    > When I was reading the PEP for code, Guido suggests using blank lines
    > 'sparingly.' Yet, in most of the 'professional' code(1) I've seen,
    > there are often HUGE amounts of whitespace, extra blank lines, and so
    > on. Is this the norm?


    Take a look at the modules included with the Python standard library. I
    think you'll find that whitespace is used conservatively, but
    appropriately. I tend to use more whitespace than most of this code,
    however.

    I believe Guido likes a blank line after the "class" statement. I tried
    this for a little while, but it felt like a special case, like the "one
    true brace" policy. On the other hand, I don't like double-linebreaks
    anywhere, but this seems to be pretty common with Python code (to
    separate function or class definitions). I also tend to line a lot of
    things up vertically, which Guido says is one of his pet peeves. =)

    > Has python gravitated toward more whitespace in general?


    Python ignores whitespace, except where it is significant. As far as
    Python programmers ;) I'd say it's a toss-up. I doubt you'll find
    consensus here.

    Cheers,
    Dave
    Dave Benjamin, Jun 13, 2004
    #2
    1. Advertising

  3. j_mckitrick

    Peter Hansen Guest

    j_mckitrick wrote:

    > When I was reading the PEP for code, Guido suggests using blank lines
    > 'sparingly.' Yet, in most of the 'professional' code(1) I've seen,
    > there are often HUGE amounts of whitespace, extra blank lines, and so
    > on. Is this the norm?
    >
    > Has python gravitated toward more whitespace in general?


    I can't speak for "python", but our informal coding standard
    asked for single blank lines between blocks of code that handled
    different aspects/steps of a problem, and single lines between
    functions/methods, and double blank lines between class or
    function definitions at the module level of indentation.

    Blank lines are a readability tool as much as clear indentation is.
    Depending on the definition of "sparingly", this may be the one
    piece of Guido's advice that we've ever ignored... :)

    -Peter
    Peter Hansen, Jun 14, 2004
    #3
  4. j_mckitrick

    j_mckitrick Guest

    Peter Hansen <> wrote in message > Blank lines are a readability tool as much as clear indentation is.
    > Depending on the definition of "sparingly", this may be the one
    > piece of Guido's advice that we've ever ignored... :)


    I've found myself using even more blank lines in python than C++. But
    if you look at BitTorrent, for example, the author claims blank lines
    are a nuisance. He writes very dense code, but I wonder if it would
    be easily maintainable by anyone besides him.


    jonathon
    j_mckitrick, Jun 18, 2004
    #4
  5. (j_mckitrick) wrote in message news:<>...
    > Peter Hansen <> wrote in message > Blank lines are a readability tool as much as clear indentation is.
    > > Depending on the definition of "sparingly", this may be the one
    > > piece of Guido's advice that we've ever ignored... :)

    >
    > I've found myself using even more blank lines in python than C++. But
    > if you look at BitTorrent, for example, the author claims blank lines
    > are a nuisance. He writes very dense code, but I wonder if it would
    > be easily maintainable by anyone besides him.
    >
    >
    > jonathon


    He also does not use docstrings. I think BitTorrent code is not
    typical
    in this respect. Look at the code in the standard library if you want
    to see how the core Python developer write. Reading the modules
    written by Tim Peters
    is especially entertaining (lots of <winks> and LOL remarks ;)
    I also would take them as examples when teaching clarity in coding.


    Michele Simionato
    Michele Simionato, Jun 18, 2004
    #5
  6. j_mckitrick

    grv Guest

    (Michele Simionato) wrote in
    <>:

    > (j_mckitrick) wrote in message
    >news:<>...
    >> Peter Hansen <> wrote in message > Blank lines are a
    >> readability tool as much as clear indentation is.
    >> > Depending on the definition of "sparingly", this may be the one
    >> > piece of Guido's advice that we've ever ignored... :)

    >>
    >> I've found myself using even more blank lines in python than C++. But
    >> if you look at BitTorrent, for example, the author claims blank lines
    >> are a nuisance. He writes very dense code, but I wonder if it would
    >> be easily maintainable by anyone besides him.
    >>
    >>
    >> jonathon

    >
    >He also does not use docstrings. I think BitTorrent code is not
    >typical
    >in this respect. Look at the code in the standard library if you want
    >to see how the core Python developer write. Reading the modules
    >written by Tim Peters
    >is especially entertaining (lots of <winks> and LOL remarks ;)
    >I also would take them as examples when teaching clarity in coding.
    >
    >
    > Michele Simionato
    >


    Depends on your style really. A comment to the right of the piece of code
    or above it if it's describing more than 1 step, serves the same purpose as
    breaking atomic groups of code with whitespace. Plus then you have a
    concise comment which can be read much faster than figuring out 4-5 lines
    of python mentally.
    grv, Aug 4, 2004
    #6
    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. Divyang M
    Replies:
    4
    Views:
    677
    Divyang M
    Aug 8, 2005
  2. Luigi Donatello Asero

    Re: Check keyword density for URL with https

    Luigi Donatello Asero, Jan 1, 2006, in forum: HTML
    Replies:
    2
    Views:
    403
    Luigi Donatello Asero
    Jan 3, 2006
  3. Luigi Donatello Asero

    Re: Check keyword density for URL with https

    Luigi Donatello Asero, Jan 1, 2006, in forum: HTML
    Replies:
    2
    Views:
    358
    Luigi Donatello Asero
    Jan 2, 2006
  4. CBFalconer

    Record density of crud and spam

    CBFalconer, Nov 15, 2007, in forum: C Programming
    Replies:
    26
    Views:
    587
    Default User
    Nov 20, 2007
  5. density plot

    , Dec 11, 2008, in forum: Python
    Replies:
    1
    Views:
    713
    David Cournapeau
    Dec 11, 2008
Loading...

Share This Page