4 ms·
If you have control flow that increases cyclomatic complexity it should be visible (explicit if), not hidden in an expression (ternary operator).
by snips 14y ago
If you have control flow that increases cyclomatic complexity it should be visible (explicit if), not hidden in an expression (ternary operator).
- batista 14y agoThe if/else is no more explicit than the ternary operator. On the contrary, the ternary operator makes the specific operation (setting ONE variable) more explicit, and ensures you only set one var. Consider: if a == 1: foo = "PASS" else: foo = "FAIL" and foo = (A == 1) ? "PASS" : "FAIL" Why repeat the foo (and risk an error by mistyping it the second time, especially in a dynamic language or with type inference)? And they add the same amount of cyclomatic complexity (not that you implied otherwise, just sayin').