logoalt Hacker News

mjcohentoday at 1:58 AM2 repliesview on HN

The ternary operator is easy to nest if you put each clause on a separate line. Then it looks just like nested if-then-else.


Replies

edoceotoday at 2:28 AM

I love the ternary operator as much as anyone. But dang if it doesn't get hard to read when there is are a few, nested even.

Does that operator compile to faster assembly that if I make the same logic with verbose `if` logic? Is that a language specific outcome?

show 1 reply
spider-mariotoday at 9:36 AM

Unless you mess up its associativity, like PHP until 7.4.

https://wiki.php.net/rfc/ternary_associativity

http://phpsadness.com/sad/30