On 13 April 2018 at 16:47, Chris Angelico <[email protected]> wrote:
> Consider:
>
> pos = -1
> while pos := buffer.find(search_term, pos + 1) >= 0:
> ...
>
> Once find() returns -1, the loop terminates. Should this need to be
> parenthesized?
I've certainly been assuming that cases like that would need to be written as:
pos = -1
while (pos := buffer.find(search_term, pos + 1)) >= 0:
...
I'd write the equivalent C while loop the same way:
int pos = -1
while ((pos = find(buffer, search_term, pos + 1)) >= 0):
...
The parentheses around the assignment in C are technically redundant,
but I consider finding the matching parenthesis to be straightforward
(especially with text editor assistance), while I consider figuring
out where the next lower precedence operator appears difficult (since
I don't have the C operand precedence table memorized, and there isn't
any simple way for my text editor to help me out).
Cheers,
Nick.
--
Nick Coghlan | [email protected] | Brisbane, Australia
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/