|
|
|
|
|
by Roboprog
4570 days ago
|
|
Yep, learned that back in college, more years ago than I should admit. Experience then teaches that if the expression is complicated enough for that to matter, you've already lost. Instead, make a boolean function with explicit "short circuit" returns. // return true if we're screwed
isScrewed ( relevant parameters...):
if failure-mode-one:
return true
if failure-mode-two:
return true
if guaranteed-save-otherwise:
return false
if failure-mode-three:
return true
return false
I remember seeing a horrible "if" statement that caused many thousands of dollars worth of wasted inventory back at one job cuz the clever coder thought he know the operator precedence and was saving time and money jamming a bunch of crap on one "if" line.Now if I could just get coworkers to stop writing "fooFlag == true" and "fooFlag == false" :-) |
|