Odd truth result with in and ==
On Thu, Nov 22, 2018 at 07:54:06AM +1100, Chris Angelico wrote:
> > if item in list == item_should_be_in_list():
> > # "good" state, i.e. is true if item is in list and should be, or isn't and shouldn't.
> > ...
> If I saw this in _any_ language, I would want it to be parenthesized
> for clarity. This kind of comparison is extremely unusual, and
> benefits from not making assumptions about how comparisons chain. And
> parenthesized, it will work the same way in any language.
I tend to agree in practice, but the idealist in me wants to say
that's poppycock--every language has rules for expression evaluation
and operator precedence, and that is all the clarity that should be
required. If you don't know them, parens or not, you're going to get
it wrong some of the time, and writing superfluous code to compensate
for other people's inadequacies is irksome.
The pragmatist in me admits that there's no good argument here, and
sometimes (as in this case) "other people" is me. :(