News for hackers. Stuff that matters.
Re:What's Coming in Python 3.8 by txcwpalpha on Wednesday July 17, 2019 @05:48PM (#20464404)
This honestly makes it seem more confusing to me. The fact that there is now an operator that can only be used in certain statements just makes things more confusing. And if there really is no overlap, then why wasn't the "=" operator just extended to also work in expressions? "while chunk = read()" seems like it makes just as much sense without adding the confusion of another operator.
Re:What's Coming in Python 3.8 by ericdevries on Wednesday July 17, 2019 @05:53PM (#20464432)
One of the good things about not using the "=" operator is that you cannot accidentally turn a comparison into an assignment, a feature that is a common cause of errors in other languages that do support it. By adding a completely different character to the operator it is not very likely to cause bugs, compared to just forgetting to type that second =
Re:What's Coming in Python 3.8 by bluecalm on Thursday July 18, 2019 @02:17AM (#20467229)
Is it really that common? I made this typo a few times in my life. It was corrected every time before the program actually run because the compiler warned me about it. I don't see how you can make this mistake if you're not aggressively trying (by turning off warnings for example).
Re:What's Coming in Python 3.8 by ericdevries on Thursday July 18, 2019 @03:57AM (#20467736)
I guess it is not common, but by using the = operator you would not get the warning, and instead get unexpected behaviour.
Re:What's Coming in Python 3.8 by RaptorJ on Wednesday July 17, 2019 @05:57PM (#20464458)
I expect the PEP authors want to avoid the "while chunk == read()" class of bugs

ninjaedit: indeed https://www.python.org/dev/peps/pep-0572/#why-not-just-turn-...

Re:What's Coming in Python 3.8 by benchaney on Wednesday July 17, 2019 @06:18PM (#20464609)
And also the converse (but no less dangerous) "if value = true"
Re:What's Coming in Python 3.8 by dragonwriter on Wednesday July 17, 2019 @06:51PM (#20464837)
> The fact that there is now an operator that can only be used in certain statements just makes things more confusing

The new operator (like many Python operators) can only be used in expressions (statements can contain expressions, but expressions are not a subset of statements.)

> The fact that there is now an operator that can only be used in certain statements just makes things more confusing

Because the “=” operator is the thing that defines an assignment statement. Even if this could be resolved unambiguously for language parsers, so that “statement defining” and “within expression” uses didn't clash, it would be create potential readability difficulties for human reading. Keeping them separate makes the meaning of complicated assignment statements and assignment-including expressions more immediately visually clear.

Re:What's Coming in Python 3.8 by txcwpalpha on Wednesday July 17, 2019 @06:59PM (#20464898)
>it would be create potential readability difficulties for human reading

I think the major argument (at least, the one I see most frequently) is that the walrus operator does create readability difficulties for humans, which is exactly why many people view it as non-pythonic. This is one of the few times I've seen someone argue that ":=" makes things more readable.

Re:What's Coming in Python 3.8 by dragonwriter on Wednesday July 17, 2019 @07:07PM (#20464947)
An argument against expression assignment is that it can create readability problems compared to separating the assignment from the expression in which the value is used. Even most supporters of the feature agree that this can be true in many cases and that it should be used judiciously.

This is in no way contrary to the argument that the walrus operator improves readability of expression assignments compared to using the same operator that defines assignment statements.