473,799 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code density

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
Jul 18 '05 #1
5 1811
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
Jul 18 '05 #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?

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
Jul 18 '05 #3
Peter Hansen <pe***@engcorp. com> 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
Jul 18 '05 #4
j_*********@big foot.com (j_mckitrick) wrote in message news:<ec******* *************** ****@posting.go ogle.com>...
Peter Hansen <pe***@engcorp. com> 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
Jul 18 '05 #5
grv
mi************* **@poste.it (Michele Simionato) wrote in
<95************ **************@ posting.google. com>:
j_*********@bi gfoot.com (j_mckitrick) wrote in message
news:<ec****** *************** *****@posting.g oogle.com>...
Peter Hansen <pe***@engcorp. com> 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.
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1273
by: Steve_CA | last post by:
Hi all, I've been doing some work trying to tune indexes in a couple of fairly large tables that are slow for us to query. I've already gotten some great suggestions from this group and they're much appreciated. One thing I did to try and gather objective stats is run "DBCC SHOW_STATISTICS". The question I have is on interpreting the results, particularly when it comes to "Density". I read the docs in Books Online and it tells me,...
3
1684
by: max khesin | last post by:
There has been a long argument as to whether high link density is good for the users. Some say it is, as it contains more information, the others say it is confusing. There is statistical study support for both .. I am just wondering if having the main body in a column and putting the relevant links in a sidebar may be a healthy compromise, have you seen this style? thanks, max
11
3772
by: hasadh | last post by:
Hi, is the assemly code for if..else and switch statements similar. I would like to know if switch also uses value comparison for each case internally or does it jump to the case directly at the assembly level ? for a performance critical application is it better to to use switch case or accomplish the same using fn pointers ?
82
4451
by: Edward Elliott | last post by:
This is just anecdotal, but I still find it interesting. Take it for what it's worth. I'm interested in hearing others' perspectives, just please don't turn this into a pissing contest. I'm in the process of converting some old perl programs to python. These programs use some network code and do a lot of list/dict data processing. The old ones work fine but are a pain to extend. After two conversions, the python versions are...
93
3909
by: Phlip | last post by:
C++ers: Feast your eyes: void Home:: inherits (IdentifierPtr const& id) { ... }
53
3196
by: jaso | last post by:
Can you give any comments on this code? I used one goto, is it bad? #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <assert.h> #define NOT_NULL 1
23
2418
by: Babak | last post by:
Hi Everyone, I've written a standard C code for a simple finite element analysis in MSVC++ . When I save the file as a cpp file, it compiles and runs perfectly, but when I save it as a c file, there are lots of errors and warnings in compiling stage. I am really confused about this problem because I'm not even familiar with C++ and my code only includes simple C functions. Can anybody please tell me what's my mistake? Is there any other...
3
3325
by: arda | last post by:
does someone know that ANSI C has a power density function or not? if not how can i achieve to do it ? or is there anyplace that i can find some info about it
0
996
by: ric3031urbina | last post by:
systimax high density patch panel http://cracks.00bp.com F R E E
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.