Code density

J

j_mckitrick

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
 
D

Dave Benjamin

j_mckitrick said:
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
 
P

Peter Hansen

j_mckitrick said:
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
 
J

j_mckitrick

Peter Hansen said:
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
 
M

Michele Simionato

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
 
G

grv

(e-mail address removed) (Michele Simionato) wrote in
(e-mail address removed) (j_mckitrick) wrote in message


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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top