in reply to if else and not reachable coding style
Example 3. It reduces nesting.
I often invert the sense of a condition so that the shorter code block is the controlled block and early exit at the end of that block so that the following code needent be indented:
if (isTrue) { # long piece of convoluted code } else { # short piece of simple code }
becomes:
if (isFalse) { # short piece of simple code # early exit (return or last) } # long piece of convoluted code
|
|---|