On 10-11-25 09:25 AM, Igor Bukanov wrote:
On 24 November 2010 17:04, Graydon Hoare<[email protected]> wrote:
It would be possible, but I get a little tingle about "doing the wrong
thing" when considering adding expression forms that perfectly mirror
statement forms.
IMO it is easier to follow
auto x = foo() ? 10 : 11;
rather than
auto x = if (foo()) { 10 } else { 11 };
Ok. Well, ternary is ... sort of orthogonal to the entire discussion of
"how to solve the general statement-in-expression-context problem". So
let's do a secondary survey perhaps:
Who feels like adding a ternary operator?
The ternary operator is Not The Most Popular Idea from C
The worst abuses that I have seen came from the use of the comma to
initialize the temporaries in the middle of the nested ?. Without the
comas it is harder to write ugly ternaries.
Oh yeah, I didn't necessarily mean "prone to abuse", just "not widely
copied". But then I went and checked and that's not true; lots of
languages picked it up.
So I guess it's just a personal bias. I don't like the ternary operator;
I was raised in lisp-land and it always felt like a less-legible variant
of better expressions. :)
Besides which, it implies control flow; it doesn't actually evaluate both
arms. So we'd be desugaring it anyway, the way we desugar&& and || in
rustboot. See above wrt. "awkward for all parties".
That would be an argument if rust would not have&& and ||. But with
latter available the control flaw implied by the ternary does not look
like an issue IMO.
It's an argument that it falls into the same category as || and &&,
nothing deeper. Maybe I wasn't clear; I realize they have control flow
as well. I wrote the desugaring code in rustboot :(
-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev