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

I'm sad to hear they finally fixed this ridiculous behavior: https://wiki.php.net/rfc/ternary_associativity


On the other hand, nested ternaries are pretty awful even when they work as expected.


They're quite readable IMO, in the right context (in languages other than PHP)

   double piecewise(double x) 
   { 
     return x < 0 ? x*x : 
            x < 1 ? x   : 
            x < 5 ? x*x-x+1 : 
                    21.
   }


That'd be fine if your debugger let you set a breakpoint on the 'x*x-x+1' bit.


Ternaries are just a mistake, period.


I use them all the time, as long as they can be written legibly.

  $result = $someCondition
    ? $foo->abc()
    : $foo->def();
To me that's much nicer than an if statement.


I'd kinda like to see a language that allowed ternaries but only when the components were sufficiently simple, e.g. no compound ternaries or even no more than a single arithmetic/boolean operator. Though enforcing it with linter rules is probably the better option.


The problem with ternaries is people getting so excited about it they build some one line monstrosities that really should be broken down into more lines

And for what's not a monstrosity to begin with... It's not a monstrosity to begin with, you ain't gaining much


I believe parent commenter was thinking of if expressions, which are quite similarly short - and I’m also on the opinion that they are much more readable and less prone to mistakes (like how does nested ternaries operate in your given language)




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

Search: