[Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
Steven D'Aprano
steve at pearwood.info
Thu Apr 26 02:10:00 EDT 2018
On Wed, Apr 25, 2018 at 10:14:11PM -0700, Łukasz Langa wrote:
> So only use the Pascal one in expressions. But don't forget
> parentheses, otherwise it will bind the thing you probably didn't want
> anyway.
Binding expressions are no worse than any other expression: sometimes
you need to bracket terms to change the default precedence, and
sometimes you don't.
And sometimes, even if we don't *need* parens, we use them anyway
because it makes the expression easier to read and understand.
Unless you have a language with no operator precedence at all, a purely
left-to-right evaluation order like Forth or (I think?) APL, there will
always be circumstances where parens are needed. Criticising binding-
expressions for that reason, especially implying that we must always use
parens, is simply FUD.
[...]
> As soon as we have to wrap a part of an expression in parentheses,
> parsing the entire thing becomes more complex.
Unless it becomes less complex to read and understand.
I for one always have difficulty parsing complex boolean tests unless I
bracket some or all of the parts, even when they're not strictly needed.
Consequently I try very hard not to write complex bool tests in the
first place, but when I can't avoid it, a few extra brackets really
helps simplify the logic.
> Often enough it will
> cause the expression to exceed whatever line length limit the codebase
> pledged not to exceed, causing one line to become three.
Just how often are your lines within two characters of the maximum
column so that adding a pair of brackets () will "often enough" put it
over the limit? Seems pretty unlikely to me. This sounds really like
picking at straws.
--
Steve
More information about the Python-Dev
mailing list