I have always written my if statements like this when I want the negative condition to enter me into the if block.
Example 1
if(condition == false){}
However, we just hired a new senior on the team that insists we should refactor to
Example 2
if(!condition){}
and use that moving forward.
I find example #1 to be easier to reason especially when checking a nested property.
e.g. if(person.name.middle.hasValue == false){}
Question What example is better to practice? or is there a better practice than either example?
Edit Scope
please limit answers to Negative conditions only. of course if(condition == true){}
is worst than if(condition){}
Because the == true
is redundent for the true case but not the false case.