On 10-11-25 11:39 AM, Patrick Walton wrote:
On 11/25/2010 11:00 AM, Graydon Hoare wrote:
Who feels like adding a ternary operator?

Not I. My instinctive argument against it is that if-then-else is the
weaker of the two branching constructs we have in the language. The more
powerful one (eventually) will be the "alt" construct, which allows the
programmer to do everything that "if" does via pattern guards, as well
as allowing destructuring and pattern matching on data values. Blessing
"if-then-else" but not "alt" with the expression form seems strange to me.

I think Igor's argument is merely one of brevity: by analogy to || and &&, it's "very terse" sugar for a short conditional structure you wind up writing a lot, not a general solution to general conditionals.

IOW, I think the issue should be considered completely independent of how we solve statements-in-expression-contexts. We have to solve the latter *anyways*, and with any of the proposed solutions to that more-general problem, I suspect Igor -- perhaps others as well -- will still want a ternary operator for brevity's sake.

It's a valid point, if you wind up writing lots of short ternary expressions. They're definitely shorter than if/then/else. The fact that I don't like it or use it much doesn't negate its presence in C, C++, C#, Java, Javascript, Perl, PHP and Ruby. Someone out there loves it.

(We're also probably going to wind up gaining ++ and --, for the same sort of reason. Too many copies of "x += 1" and you just naturally start to itch for it.)

-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to