A desperate lunge for on-topic-ness

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Oct 18 21:34:07 EDT 2012


On Thu, 18 Oct 2012 15:59:18 +0200, Jean-Michel Pichavant wrote:

> ----- Original Message -----
>> On 2012-10-18, Zero Piraeus <schesis at gmail.com> wrote:
>> 
>> > What are people's preferred strategies for dealing with lines that go
>> > over 79 characters? A few I can think of off the bat:
>> 
>> I try to do what's easiest to read and understand.  Sometimes that
>> means using a line thats 120 characters long, sometimes that means
>> breaking up the line.
>>
>>
> Imo, def. a good approach to the problem. Mark's also pointed the fact
> that the guidelines themselves state that rules are made to be broken
> when they need to be. The 79 char limit purpose is to allow someone to
> read the code on a 80 char terminal (and allow old printers to print the
> code). 

And people who like to have multiple windows open side-by-side.

And people who may have some need to email or post code inline rather 
than as attached files (say, on this list).

And people who may need to run external tools over their code (e.g. grep, 
diff) and view the output in a terminal with, say, 120 character width. 
This allows ~80 characters for the source and ~40 characters for whatever 
extraneous information the tool displays on the same line.

And, quite frankly, people who care more about the readability of their 
code than about squeezing in as much processing into a single line of 
text as possible.

In my not-in-the-slightest-bit-humble opinion, if someone is consistently 
needing more than 79 characters per line, they're probably doing one or 
more of the following coding sins:

- using one-liners for the sake of one liners;
- code that is too deeply nested (if you need more than 3 or 4 indents
  for a block, you're probably doing something wrong);
- doing too much in one line, e.g. overly busy list comps;
- excessively long variable or function names;
- badly designed functions or classes that take too many arguments;
- misuse of Hungarian Notation; and
- violations of the Law of Demeter.

Or possibly they're just unlucky to require a library with excessively 
long names and can't do much about it.

I'm not saying that every line that exceeds 79 characters is crap, but I 
am saying that if you have trouble keeping *at least* 90% of your code 
under 79 characters, you may very well be suffering from poor design, 
lousy code, or both.

Flame away :)



-- 
Steven



More information about the Python-list mailing list