News for hackers. Stuff that matters.
Re:The Year of C++ Successor Languages by tialaramex on Monday January 02, 2023 @05:17PM (#34224472)
The crucial thing about Try (the ? operator) is actually pretty easy to see if you look at the Trait which makes it go:

The result of the branch method on Try is ControlFlow<Self::Residual, Self::Output>

Try isn't stable, but ControlFlow is. They've reified the control flow! Rust has a type which represents the idea of a decision whether to return early. This is in my opinion pure genius, and it happened almost by accident. It seemed natural at first that the decision to return early is manifested directly in Result, but it isn't. That's the insight. Failure and returning early are distinct ideas, and we might just as easily want to return early in consequence of success as failure.

In separating "Success versus Failure" from "Return early versus keep going" Rust gets a lot more value here than is encapsulated in C++ Exceptions.

There are no comments on this comment yet.