On Thu, 26 Apr 2018 08:38:51 +1000 Chris Angelico rosuav@gmail.com wrote:
On Thu, Apr 26, 2018 at 8:08 AM, Antoine Pitrou solipsis@pitrou.net wrote:
On Wed, 25 Apr 2018 16:55:43 -0500
Tim Peters tim.peters@gmail.com wrote:
>
To my eyes, this is genuinely harder to follow, despite its relative brevity:
while total != (total := total + term):
Does it even work? Perhaps if the goal is to stop when total is NaN, but otherwise?
Yes, it does, because the first "total" is looked up before the rebinding happens. It's 100% unambiguous to the compiler... but still pretty unclear to a human. And I think the multiple use of 'total' is to blame for that. So I agree with Tim that this particular example is better in longhand.
"Better" is an understatement :-( Now that I understood it (thanks for the explanation), the shorthand version appears completely bonkers.
Regards
Antoine.