I seem to see this often enough in my code and others. There's nothing about it that seems horribly wrong, but it annoys me as it looks like it can be done better. I suppose a case statement, might make a little more sense, but often variable is a type that does not work well or at all with case statements (depending on language)
If variable == A
if (Flag == true)
doFooA()
else
doFooA2
else if variable == B
if (Flag == true)
doFooB()
else
doFooB2
else if variable == C
if (Flag == true)
doFooC()
else
doFooC2
It seems there's multiple ways to "factor" this, such as 2 sets of if-elses, where one set handles when Flag == true.
Is there a "good way" to factor this, or perhaps when this if-else algorithm happens it usually means you are doing something wrong?
if (Flag == true)
rather than justIf (Flag)
? If you think thatIf (Flag == true)
is better, why notif ((Flag == true) == true)
?