DEV Community

Discussion on: We don't need a ternary operator

Collapse
 
codevault profile image
Sergiu Mureşan • Edited

It could be that calling it an operator is simply confusing.

Coffeescript has a

if (b < 5) then b else 5

Which makes it look more like an inline if that returns its values from the if or else block.

So, the conditional operator would be more like:

let a = (function() { 
    if (b < 5)
        return b;
    else
        return 5;
})();

I really like the solution though, it makes so much more sense to have it be made up of binary operators now. It doesn't even make sense to add the conditional operator back in since the ? and | are already fully encompassing its use cases.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

I really dislike the inline if ... else forms that some languages have, also including Python. It looks really messy, and more like a flow statement than an expression.