Home  >  Article  >  Backend Development  >  如何看待 2016 年 5 月 3 日 Python PEP8 风格的改动?

如何看待 2016 年 5 月 3 日 Python PEP8 风格的改动?

WBOY
WBOYOriginal
2016-06-06 16:23:221316browse

2016年5月3日 PEP8 发了一版更新:PEP 8 -- Style Guide for Python Code,同事在进行代码检查的时候被发现,之前写的 if 条件被爆风格错误, 原因是 and被放在了分行的开头,在新的PEP8规范里 建议将 and 放在一行结尾,理由为换行更明确,但放在前面应该更清晰语句之间的关系呀,大家如何看待 and在if条件的位置,以及这次的更新?

回复内容:

PEP 8在2016年4月15日发布了一版更新,将原来规定的「换行符应该放在二元运算符之后」改成了「换行符建议放在二元运算符之前」。

看了下更新的理由,似乎是有人考古挖出了Donald Knuth大爷的著作"The TeXbook",然后发现书中Displayed Equation一章里Knuth表示公式在多行的情况下理应把换行符放在二元或关系运算符之前:
如何看待 2016 年 5 月 3 日 Python PEP8 风格的改动?
这么做的理由似乎是显得更加易读,比如PEP 8里给的例子:
<code class="language-text">income = (gross_wages +
          taxable_interest +
          (dividends - qualified_dividends) -
          ira_deduction -
          student_loan_interest)
</code>
用pycharm没有波浪线就看着舒服 瞎折腾。。。 原来的PEP风格 +1
破Python吃枣药丸 +1
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn