Python PEP 8 docstring行长度
我最近开始计算,这是一个好主意,按照PEP 8.我让我的编辑器显示80列标记,我现在试图包装线适合它。我的问题是这个。在PEP 8中它说:
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:
限制所有行最多包含79个字符。
Limit all lines to a maximum of 79 characters.
有意义。
[...]评论),建议将长度限制为72个字符。
[...] For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended.
为什么选择72?
我相信这是文本文档的宿醉:
I believe it's a hangover from text documents:
在打字机时代结束时,大多数设计都面向72
CPL,来自每英寸12个字符的音高乘以6
英寸(例如参见IBM Selectric)。这将确保每个保证金至少1
英镑,美国政府当时在8 1/2×11纸上标准化
。
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.
许多纯文本文档仍然符合传统的72 CPL。
Many plain text documents still conform to 72 CPL out of tradition.
docstrings通常用在代码之外的上下文中,所以符合大多数纯文本文档使用的样式并尽可能保持一致是有意义的。例如, man
页面通常被包装到72个字符。通过限制文档字符串为72个字符, help()
的输出镜像这个。
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.
这个问题对于程序员也可能是相关的。