Hacker News new | ask | show | jobs
by barrkel 4800 days ago
That has nothing to do with the semantics ternary operator per se, but rather to do with how Java and C++ respectively type it. If you inserted the relevant casts to make sure both result halves have the same type, the difference would disappear.

You could expose the same semantic difference your example relies on with overload resolution, without needing to refer to the ternary operator at all. But I hope you wouldn't take that to mean that overloads are also a bad idea.

I also believe that the ternary operator is particularly nice when used in combination:

    x = a ? foo :
        b ? bar :
        c ? baz :
            blah;
The idiom tastes a little like pattern matching. Of course, you need to be a little cautious about your precedence, but I've never used a language supporting infix operators that didn't have gotchas around precedence.