A desperate lunge for on-topic-ness

S

Steven D'Aprano

The accepted rule in print is that lines of prose should be between 45
and 90 characters, with 66 being ideal for readability. Code is not
prose, and the combination of fixed-width and much more variable line
length aids readability, but however it came about, ~80 does seem to
more or less work as a limit.

On the other hand, code is typically *much* harder to understand than
normal prose.

On the third hand, the "chunks" of semantic meaning in code is
significantly greater -- you can often ignore 99% of the code and just
skim past it, and so not even notice long line lengths until you get to
the specific few lines you care about. But once you reach the lines you
care about, or *might* care about, horizontal space is costly and
vertical space is cheap.

So reading code often has two distinct phases: skim and inspect. When
skimming, vertical space is at a premium, and you want to fit as much
code as possible in as few lines as possible. When inspecting code
closely, you want to fit as little code as practical in each line. So
there's a trade-off.

But for anything but the most horribly obfuscated code, it is much easier
to identify bits of code that are irrelevant to your problem than to
identify which bit of code is specifically causing the bug. So skimming
is inherently easier than close study (well duh). Consequently it is wise
to optimise your code layout for the hard parts, not the easy parts, and
so you should treat vertical space is cheaper than horizontal space, and
try to keep your line length down.

And note that, even when writing, most of your time is problem spent in
writing what is already there. Coding is rarely like typing out dictation.
 
R

rusi

 \       “When I get new information, I change my position. What, sir, |
  `\             do you do with new information?” —JohnMaynard Keynes |
_o__)                                                                 |
\ “Anyone who believes exponential growth can go on forever in a |
`\ finite world is either a madman or an economist.” —Kenneth |
_o__) Boulding |

I am amused by the juxtaposition of these two signatures --
considering that Keynes was an economist
 
K

Krzysztof Voss

:



Okay, so, first thing vaguely Python-related that comes to mind [so

probably not even slightly original, but then that's not really the

point]:



What are people's preferred strategies for dealing with lines that go

over 79 characters? A few I can think of off the bat:



1. Say "screw it" and go past 79, PEP8 be damned.
Once you ":set cc=79", you never want to cross it.
2. Say "screw it" and break the line using a backslash.



3. Say "well, at least it's not a backslash" and break the line using

parentheses.
Some nice, IMHO, tips on the style can be found in:
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Line_length


Cheers!
 
K

Krzysztof Voss

:



Okay, so, first thing vaguely Python-related that comes to mind [so

probably not even slightly original, but then that's not really the

point]:



What are people's preferred strategies for dealing with lines that go

over 79 characters? A few I can think of off the bat:



1. Say "screw it" and go past 79, PEP8 be damned.
Once you ":set cc=79", you never want to cross it.
2. Say "screw it" and break the line using a backslash.



3. Say "well, at least it's not a backslash" and break the line using

parentheses.
Some nice, IMHO, tips on the style can be found in:
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Line_length


Cheers!
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top