5 ms·
On the other hand, nested ternaries are pretty awful even when they work as expected.
by dabernathy89 4y ago
On the other hand, nested ternaries are pretty awful even when they work as expected.
- TylerE 4y agoTernaries are just a mistake, period.
- dabernathy89 4y agoI 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.
- cozzyd 4y agoThey'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. }
- wizofaus 4y agoThat'd be fine if your debugger let you set a breakpoint on the 'x*x-x+1' bit.