if
statements with conditions that are always false have the effect of making blocks of code non-functional. if
statements with conditions that are always true are completely redundant, and make the code less readable.
There are three possible causes for the presence of such code:
- An if statement was changed during debugging and that debug code has been committed.
- Some value was left unset.
- Some logic is not doing what the programmer thought it did.
In any of these cases, unconditional if
statements should be removed.
Noncompliant code example
if true {
doSomething()
}
if false {
doSomething()
}
Compliant solution
doSomething();
...