[Python-Dev] PEP 572: Assignment Expressions
Sven R. Kunze
srkunze at mail.de
Mon Apr 23 17:25:42 EDT 2018
On 23.04.2018 22:37, Chris Angelico wrote:
> Ah, are you one of those programmers who writes code once and it's
> instantly perfect? I apologize, I didn't realize I was in the presence
> of a unicorn.
Wow, constructive. Nothing is perfect, but if you don't consider your
surroundings when doing changes, well, what could possibly go wrong...
> Duplication works against that by forcing you to make changes in two places.
... in the very same line, a line below, few characters after/before it.
> I've seen code that relies on duplication and compiler optimizations.
> Sure, it'll run just as fast as the equivalent with actual variable
> names; but that's beside the point. It takes extra effort to maintain
> such code, and that is what matters.
That's exactly my point. Readability is what counts, especially for
maintaining. "gcd(diff, n)" is a great name, much better than "g", if
you ask me.
We aren't talking about 1000 lines of code here. The new syntax will
enable one-liner optimizations. And I think Tim's example is as good as
we can get realistically. Because if the expressions become longer or
more complex and/or the numbers of expressions increase, I doubt that a
majority want to have that in a single line even though the syntax would
allow this. And if so the editor might include some line wraps, so then
we are where we were before. Somewhere, you need to get your hands dirty.
More information about the Python-Dev
mailing list