As the topic states, sometimes these issues conflict. For example…
In this case, the nominal case is first, but the expression is negative.
if ( !foo.IsDead() ) {
DoThis();
} else {
DoThat();
}
In this case, the expression is positive, but the nominal case is last.
if ( foo.IsDead() ) {
DoThat();
} else {
DoThis();
}
Of course, a third option would be to flip around the IsDead function to be IsAlive(). I’d like to hear others’ thoughts on these 3 choices when they encounter them in coding. Do you go with nominal, positive, or fix the whole thing by flipping the boolean itself.
I prefer option two as it’s slightly clearer / easier to read.
But you’re heading for religious war territory I suspect.
In terms of flipping the name of the function, I’d only change if isAlive() is the most likely outcome. That is, I think the code is clearer if the most likely outcome is your boolean expression equating to true. The least likely (false) should come second. It it’s 50/50 then I wouldn’t worry.