I’m not really sure where to bring this up, since there’s already RFCs, tracking issues, etc.
I wouldn’t be making this thread if I didn’t think this was a big deal. I’m mostly content to let the details of Rust slide, and am generally happy with the language as evolving.
However, as presented, the “?” operator promises to make Rust vastly different from other syntactically identical expressions in many other programming languages, and not even in a way that’s immediately obvious.
Ruby, C#, Swift, Groovy, Kotlin, and Perl 6 all have some form of “Safe navigation” or “safe call” operator. They’re all roughly invoked something like let f = foo()?.bar()?.baz();
, mostly differring in the keyword choice for let
.
Rust has proposed to add something that will look nearly identical, however it will function very differently. I know of zero other languages that do something similar. Exceptions, of course, are a related idea, but the programming language community at large has experience with them, and Rust does have panics already.
By hiding return statements in the middle of expressions, I believe Rust control flow will be very surprising to casual users of basically every other programming language. Since Rust is, at least today, a niche language, that is effectively all its users. I didn’t see any discussion on the RFCs on how this feature compares with other programming languages, and that concerns me. Rust does not exist in a vacuum.
I think having a safe call operator would make a lot of sense in Rust. In fact, let f = try!( foo().?bar()?.baz() );
could reduce noise significantly from what we have today, and replacing try!()
with syntax could make a lot of sense. But tacking a question mark on the end is way too subtle.
Having ?
hide a return
, I believe, will irreparably make Rust hard to read and learn.