In a situation where a variable can have two different values, and you do something if its one, something else, if it's different, you would just do:
if(myVariable == FIRST_POSSIBLE_VALUE) { ... }
else { ... }
or would you do:
if(myVariable == FIRST_POSSIBLE_VALUE) { ... }
else if (myVariable == SECOND_POSSIBLE_VALUE) { ... }
for clarity, in a situation where the reader may not necessarily be able to say that they are doing the same (but else if does the “unnecessary” expression)? So what would you do? Thanks!
EDIT: In fact, there are much more different options for something like this: trernary operator, if-else, if-elseif, if-elseif-else, -if-else (with assert), switch. Everyone has their own place, but it is difficult to solve.
source
share