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

Better yet, you can do stuff like

  value = if (test) {some_value * multiple}
          else if (test2) {second_value}
          else {false_value}
which falls in a straightforward way out of the if/else syntax, which the language authors have put a lot more thought into than the rarely used ?: syntax.


How about formatting the ternary thusly:

  value = test
    ? (some_value * multiple)
    : false_value;


To match, it would have to be:

  value = test ? some_value * multiple
          : test2 ? second_value
          : false_value;
Which, you know, isn't that bad. But it looks really weird since people don't expect you to use ternary that way, while multi-part if statements are fairly normal.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: