I guess the author just distrusts smaller things, leaving me to distrust the author’s larger things.
I guess the author just distrusts smaller things, leaving me to distrust the author’s larger things.
Well, assuming that the language doesn't have any quirks in this area - e.g. in Java your statements aren't equivalent for a Boolean x.
Reading "if true == false" or "if false == false", it becomes much clearer what we're testing here and I understand it instantly.
I agree that when you read it, it's clearer. And yet I still prefer "if(isGreen == false)" for reasons of clarity in another sense.
The "!" being right next to the "(" makes it easier to miss the "!" when scanning quickly through the code, hence reading the logic the wrong way round and seeing "(isGreen" instead of "(!isGreen". And that's enough of a risk to ignore the readability advantage of "(!".
(Edit: To be clear, I don't suggest "== true" for the opposite cases, as the lack of a "!" in those means the risk is gone)
if (x == true)
which always seem to come with some argument how it is "more clear".I have started to ask people straight away to change to
if ((x == true) == true)
which following the same argument should be even more clear.That said, if x is data read from elsewhere that just happens to be boolean, I can write code like that in Python.
if !is_nil(foo)