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

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



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: