Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PEP 8 docstring line length [closed]

I've recently begun figuring it would be a good idea to follow PEP 8. I made my editor display the 80-column mark and am now attempting to wrap lines to fit in it. My question is this. In PEP 8 it says:

Limit all lines to a maximum of 79 characters.

Makes sense.

[...] For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended.

Why 72? Why isn't 79 fine for docstrings or comments?

like image 602
Claudiu Avatar asked Mar 15 '13 17:03

Claudiu


2 Answers

I believe it's a hangover from text documents:

At the end of the typewriter age, most designs were geared toward 72 CPL, derived from a pitch of 12 characters per inch, multiplied by 6 inches (see for example IBM Selectric). This would ensure at least 1 inch for each margin, with the U.S. government at the time having standardized on 8 1/2×11" paper.

Source

Many plain text documents still conform to 72 CPL out of tradition.

I think this is just as docstrings are often used in contexts outside of code, so it makes sense to conform to the style most plain text documents use to try and remain as consistent as possible. For example, the text of man pages are generally wrapped to 72 characters. By limiting docstrings to 72 characters, the output of help() mirrors this.

This question on Programmers may also be relevant.

like image 165
Gareth Latty Avatar answered Oct 26 '22 12:10

Gareth Latty


Docstrings are typically indented with their function, and start and end with triple quotes:

def foo(bar, baz):
    """Frobnicate the foobars into baz

    Parameters are ham and spammed.

    """

That's 79 - 4 - 3 = 72 characters left.

like image 35
Martijn Pieters Avatar answered Oct 26 '22 13:10

Martijn Pieters