Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you have control flow that increases cyclomatic complexity it should be visible (explicit if), not hidden in an expression (ternary operator).


The 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').




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: