Why does PEP-8 specify a maximum line length of 79

2019-01-16 02:27发布

Why in this millennium should Python PEP-8 specify a maximum line length of 79 characters?

Pretty much every code editor under the sun can handle longer lines. What to do with wrapping should be the choice of the content consumer, not the responsibility of the content creator.

Are there any (legitimately) good reasons for adhering to 79 characters in this age?

标签: python pep8
10条回答
冷血范
2楼-- · 2019-01-16 02:56

because if you push it beyond the 80th column it means that either you are writing a very long and complex line of code that does too much (and so you should refactor), or that you indented too much (and so you should refactor).

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-16 02:56

I agree with Justin. To elaborate, overly long lines of code are harder to read by humans and some people might have console widths that only accommodate 80 characters per line.

The style recommendation is there to ensure that the code you write can be read by as many people as possible on as many platforms as possible and as comfortably as possible.

查看更多
【Aperson】
4楼-- · 2019-01-16 02:57

Here's why I like the 80-character with: at work I use Vim and work on two files at a time on a monitor running at, I think, 1680x1040 (I can never remember). If the lines are any longer, I have trouble reading the files, even when using word wrap. Needless to say, I hate dealing with other people's code as they love long lines.

查看更多
Melony?
5楼-- · 2019-01-16 03:02

79 characters (well, actually 72 characters) is where most text-based email readers linewrap. So code cut-and-pasted into an email is a lot more readable.

查看更多
登录 后发表回答