News for hackers. Stuff that matters.
Re:Clear is better than clever [pdf] by bobbylarrybobby on Monday May 06, 2019 @10:10AM (#19839530)
Nested ternary is fine as long as it’s written on multiple lines because then it exactly mirrors the if/else-if/else structure.

    return (
        a < b ?
        -1 :
        a > b ?
        1 :
        0)
Re:Clear is better than clever [pdf] by macspoofing on Monday May 06, 2019 @07:16PM (#19844897)
>then it exactly mirrors the if/else-if/else structure.

But it doesn't mirror the if/else-if/else structure. Rather the mirrored semantics looks as follows:

  if(a < b)
    return -1;
  else 
    if(a > b)
      return 1;
    else
      return 0;
It's interesting that for all the claims in this thread about how obvious the ternary operator is, almost every single person got it wrong.

Is there a functional difference in this example? No. There isn't. Is there a functional difference in any example? I don't think so, but I'm not 100% sure. And the nice thing about not being clever, I don't have to worry about it.