This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maggyero
Recipients docs@python, maggyero
Date 2019-08-10.21:46:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1565473572.7.0.81062665759.issue37813@roundup.psfhosted.org>
In-reply-to
Content
I have just read PEP 7 and noticed that its line-breaking recommandation in presence of binary operations seems to contradict its analogue in PEP 8 which follows Knuth's rule.

PEP 7 (https://www.python.org/dev/peps/pep-0007/#code-lay-out):

> When you break a long expression at a binary operator, the operator
> goes at the end of the previous line, and braces should be formatted
> as shown. E.g.:
> 
> if (type->tp_dictoffset != 0 && base->tp_dictoffset == 0 &&
>     type->tp_dictoffset == b_size &&
>     (size_t)t_size == b_size + sizeof(PyObject *))
> {
>     return 0; /* "Forgive" adding a __dict__ only */
> }

PEP 8 (https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator):

> To solve this readability problem, mathematicians and their
> publishers follow the opposite convention. Donald Knuth explains the
> traditional rule in his Computers and Typesetting series: "Although
> formulas within a paragraph always break after binary operations and
> relations, displayed formulas always break before binary operations"
> [3].
> 
> Following the tradition from mathematics usually results in more
> readable code:
> 
> # Yes: easy to match operators with operands
> income = (gross_wages
>           + taxable_interest
>           + (dividends - qualified_dividends)
>           - ira_deduction
>           - student_loan_interest)
> In Python code, it is permissible to break before or after a binary
> operator, as long as the convention is consistent locally. For new
> code Knuth's style is suggested.
History
Date User Action Args
2019-08-10 21:46:12maggyerosetrecipients: + maggyero, docs@python
2019-08-10 21:46:12maggyerosetmessageid: <1565473572.7.0.81062665759.issue37813@roundup.psfhosted.org>
2019-08-10 21:46:12maggyerolinkissue37813 messages
2019-08-10 21:46:12maggyerocreate