3 ms·
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
by dabernathy89 4y ago
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.
- kaba0 4y agoI 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)
- Dudeman112 4y agoThe 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
- wizofaus 4y agoI'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.