Re:What's Coming in Python 3.8
by chrisseaton on Wednesday July 17, 2019 @05:56PM
(#20464447)
So := is 'gets a truthy value from'? That seems to work.
> For what it's worth, "x = y()" is one of the harder things for new programmers to translate to English in the first place
Right... so why have we added more complexity to something known to be very complicated?
Re:What's Coming in Python 3.8
by dragonwriter on Wednesday July 17, 2019 @07:02PM
(#20464918)
> So := is 'gets a truthy value from'?
No, “if <expression>” expands to “if <expression> has a truthy value”.
“<var> := <expression>” is itself an expression, which can be best (IMO) read in English as “<var> (which is <expression>)”
How about "assigns to and returns"?
we added new syntax for a code pattern that has inherent complexity which can't be reduced.
Re:What's Coming in Python 3.8
by chrisseaton on Wednesday July 17, 2019 @06:13PM
(#20464578)
It can be reduced into two simpler lines can’t it, both of which could be understood in isolation.
understanding lines in isolation is precisely besides the point here, because the code pattern has to be understood as a whole.
Re:What's Coming in Python 3.8
by chrisseaton on Wednesday July 17, 2019 @06:25PM
(#20464664)
I don’t see why. ‘Assign x’ and ‘is x truthy’ can be understood separately. Worry about what x is being assigned. Then worry about whether its value is truthy.
like I said, the whole pattern is more than two lines. the pattern is actually assign-test-fallback-test-fallback-test-etc.
to quote the PEP:
reductor = dispatch_table.get(cls)
if reductor:
rv = reductor(x)
else:
reductor = getattr(x, "__reduce_ex__", None)
if reductor:
rv = reductor(4)
else:
reductor = getattr(x, "__reduce__", None)
if reductor:
rv = reductor()
else:
raise Error(
"un(deep)copyable object of type %s" % cls)
becomes: if reductor := dispatch_table.get(cls):
rv = reductor(x)
elif reductor := getattr(x, "__reduce_ex__", None):
rv = reductor(4)
elif reductor := getattr(x, "__reduce__", None):
rv = reductor()
else:
raise Error("un(deep)copyable object of type %s" % cls)
For what it's worth, "x = y()" is one of the harder things for new programmers to translate to English in the first place -- it reads most naturally as "x equals y," but leads to better intuitions as "x gets the value of y". I think that's what makes this clunky to verbalize, rather than the "if truthy" bit.