473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

About the 79 character line recommendation

As I study Python, I am trying to develop good, Pythonic, habits. For
one thing, I am trying to keep Guido's the style guide in mind.

And I know that it starts out saying that it should not be applied in
an absolute fashion.

However, I am finding that the 79 character line prescription is not
optimal for readability.

Certainly, cutting back from the length of lines that I used to use has
*helped* readability. But if I triy very hard to apply 79, I think
readability suffers. If this were just something that was an issue
occasionally, I would just put it off to "know when to break the
rules". However, find myself going to 90 to 100 characters very
frequently. Now, if it were just me, I'd shoot for < 100. However,
the Python philosophy includes making code easier for others to read,
as well.

So, I was wondering what more accomplished Python programmers thought
about this.

While I'm on this general topic, the guide mentions a pet peeve about
inserting more than one space to line up the "=" in assignment
statements. To me, lining them up, even if it requires quite a few
extra spaces, helps readability quite a bit. Comments?

Thanks,
Steve Bergman

Dec 5 '06 #1
8 1710
sam

Steve Bergman wrote:
As I study Python, I am trying to develop good, Pythonic, habits. For
one thing, I am trying to keep Guido's the style guide in mind.

And I know that it starts out saying that it should not be applied in
an absolute fashion.

However, I am finding that the 79 character line prescription is not
optimal for readability.

Certainly, cutting back from the length of lines that I used to use has
*helped* readability. But if I triy very hard to apply 79, I think
readability suffers. If this were just something that was an issue
occasionally, I would just put it off to "know when to break the
rules". However, find myself going to 90 to 100 characters very
frequently. Now, if it were just me, I'd shoot for < 100. However,
the Python philosophy includes making code easier for others to read,
as well.

So, I was wondering what more accomplished Python programmers thought
about this.

While I'm on this general topic, the guide mentions a pet peeve about
inserting more than one space to line up the "=" in assignment
statements. To me, lining them up, even if it requires quite a few
extra spaces, helps readability quite a bit. Comments?

Thanks,
Steve Bergman
I prefer to use 132 char per line, and like you I line up the = sign
for readability.
The reason for this convention arises from the fact that I am Dyslexic,
and this convention helps me double check my typing.

Sam Schulenburg

Dec 5 '06 #2
Steve Bergman wrote:
[snip]
However, I am finding that the 79 character line prescription is not
optimal for readability.

Certainly, cutting back from the length of lines that I used to use has
*helped* readability. But if I triy very hard to apply 79, I think
readability suffers. If this were just something that was an issue
occasionally, I would just put it off to "know when to break the
rules". However, find myself going to 90 to 100 characters very
frequently. Now, if it were just me, I'd shoot for < 100. However,
the Python philosophy includes making code easier for others to read,
as well.
Are you taking advantage of all the various options for line
continuation besides \ that exist in Python, like (a) automatic
concatenation of adjacent string literals (b) automatic continuation
until () [] or {} are balanced? Example using both:

fprintf(self.logfile,
"WARNING *** Conflict between "
"std format code %d and its format string %r\n",
fmtcode, unistrg)

Aside: In this most noble of languages, fprintf() has a one-line
implementation:

def fprintf(f, fmt, *args):
f.write(fmt % args)
>
While I'm on this general topic, the guide mentions a pet peeve about
inserting more than one space to line up the "=" in assignment
statements. To me, lining them up, even if it requires quite a few
extra spaces, helps readability quite a bit. Comments?
Merely aligning the = would annoy the crap out of me. However if the
RHS of a bunch of *related* assignments could be made clearer by
inserting extra space, *and* they were more complicated than the
following trivial example of what I mean, I'd do it.
red = c & 0xff
green = (c >8) & 0xff
blue = (c >16) & 0xff
c.f.
red = c & 0xff
green = (c > 8) & 0xff
blue = (c >16) & 0xff

Cheers,
John

Dec 5 '06 #3
Steve Bergman wrote:
As I study Python, I am trying to develop good, Pythonic, habits. For
one thing, I am trying to keep Guido's the style guide in mind.

And I know that it starts out saying that it should not be applied in
an absolute fashion.

However, I am finding that the 79 character line prescription is not
optimal for readability.

Certainly, cutting back from the length of lines that I used to use has
*helped* readability. But if I triy very hard to apply 79, I think
readability suffers. If this were just something that was an issue
occasionally, I would just put it off to "know when to break the
rules". However, find myself going to 90 to 100 characters very
frequently. Now, if it were just me, I'd shoot for < 100. However,
the Python philosophy includes making code easier for others to read,
as well.

So, I was wondering what more accomplished Python programmers thought
about this.

While I'm on this general topic, the guide mentions a pet peeve about
inserting more than one space to line up the "=" in assignment
statements. To me, lining them up, even if it requires quite a few
extra spaces, helps readability quite a bit. Comments?

Thanks,
Steve Bergman
I also think that limiting code to 80 columns often hinders
readability. I personally try to limit my code to 100 columns. The end
result is pretty nice.

However, I'm all for the "flat is better than nested" philosophy, even
when nested is under 100 columns.

Dec 5 '06 #4
Thanks for the responses.

The point about 132 columns is good. Pretty much any printer will
handle that today, though I reserve the right to change my mind about
the utility of 17cpi print after I'm 50. Hopefully, all printers will
be at least 1200dpi by then. ;-)

---

Yes, I dislike "\" for continuation, and use the implicit continuation
between parentheses, braces, etc. wherever possible. I don't mind
breaking up comma separated values like function method arguments, but
I very much dislike breaking at an "=" sign.

(BigLong VariableName
= BigLongMethodCallWithALotOfArguments)

Come to think of it, though, I'm working mostly in TurboGears (web
devel framework) which may not represent python code in general all
that well wrt line length. Lot's of lines that are harder to break up
than in some other environments, perhaps.

---

I'm finding 100 to be a nice balance. It forces me not to be lazy and
allow really long lines, but allows me to format so as to make the
meaning most clear.

Dec 5 '06 #5
In <11*********************@n67g2000cwd.googlegroups. com>, Steve Bergman
wrote:
While I'm on this general topic, the guide mentions a pet peeve about
inserting more than one space to line up the "=" in assignment
statements. To me, lining them up, even if it requires quite a few
extra spaces, helps readability quite a bit. Comments?
That may help readability a little bit but if one of the lines will be
changed the other lines have to be changed too which results in a diff
that masks the "real" change a bit. If just one line changes it's easier
to read and follow diffs from version control systems.

Ciao,
Marc 'BlackJack' Rintsch
Dec 5 '06 #6
Olivier Langlois wrote:
There was a coding standard where I worked and the intention behind this
requirement was to make the code printer friendly. Printing code source
with lines longer than 80 chars greatly hinder readability on paper.
I don't think I've ever seen Python code printed out other than in
books. Indeed, I don't think I've seen anyone print their code in any
language in a decade--it's much easier to read online with tags, class
browsers, easy access to version history, etc.

The 79-column limit is a hard rule most places I've worked, because
pretty much all code is going to wind up with someone looking at it on
an 80-column terminal at some point.

Dec 6 '06 #7
Steve Bergman wrote:
>
So, I was wondering what more accomplished Python programmers thought
about this.
I *hate* people using more than 79 chars per line! ;) They look
horrible in emacs
and horrible on print. I never found the need for longer lines. The
limit also acts
as a deterrent against extra-large one-liners.

Finally, notice that you can alwasys aliases if you are a lazy typist:

shortcut = LongClassName.LongAttributeName

This also saves an attribute access and gives you some additional
speed, which may
be useful in some cases.

Michele Simionato

Dec 6 '06 #8
On 5 Dec 2006 13:28:22 -0800, Steve Bergman <st***@rueb.comwrote:

(...)
>
I'm finding 100 to be a nice balance. It forces me not to be lazy and
allow really long lines, but allows me to format so as to make the
meaning most clear.


But if you use some advanced editors (such as Emacs) that easily allow
you to see/edit the same file in two buffers side by side, then going
beyond 80 chars is often a bad idea, specially if you use a laptop.
(And, of course, there is the eternal issue of doing a simple "a2ps"
to print some code; longer than 80 and you often have hard to read
pages).

Best,

R.

--
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
Dec 6 '06 #9

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

Similar topics

38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
76
by: Zenobia | last post by:
How do I display character 151 (long hyphen) in XHTML (utf-8) ? Is there another character that will substitute? The W3C validation parser, http://validator.w3.org, tells me that this character...
36
by: Peter Brause | last post by:
Hello, my stylesheet shows different colors for visited, active and hovered links. It works fine in IE 6, but in Opera 7 the color for the active link (red background) is never shown. How to...
5
by: Paul | last post by:
I've bought two books on CSS, and found they're no good. Now I'm reading "Cascading Style Sheets, level 2 revision 1 CSS 2.1 Specification" , but it's tough going. I have lots of questions about...
2
by: jagivens | last post by:
Hi, I have two identical programs that encrypt characters. One is written in C++, and it works, but the other one is written in C, and it does not work. I have copied the code below. There is...
18
by: David Buchan | last post by:
Hi guys, This may be a dumb question; I'm just getting into C language here. I wrote a program to unpack a binary file and write out the contents to a new file as a list of unsigned integers....
33
by: Lalatendu Das | last post by:
Dear friends, I am getting a problem in the code while interacting with a nested Do-while loop It is skipping a scanf () function which it should not. I have written the whole code below. Please...
5
by: hn.ft.pris | last post by:
Hi: I'm a beginer of STL, and I'm wondering why none of below works: ######################################################################## .......... string str("string"); if ( str == "s" )...
6
by: Paddy3118 | last post by:
Hi, I am trying to find out if thhe following snippet would be valid XML - specifically the use of '>' between the tags: <expressionA>=B </expression> Should it be: <expressionA&gt;=B...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.