3 ms·
This reads a lot like Rust does it's error-handling too.
by Bromeo 5y ago
This reads a lot like Rust does it's error-handling too.
- b0sk 5y agoRight. I think Rust was the first to propose “?” operator as a syntactic sugar to Result and Option monads. (i am not 100% though) ref: https://m4rw3r.github.io/rust-questionmark-operator https://m4rw3r.github.io/rust-questionmark-operator
- square_usual 5y agoRuby got the safe navigation operator (&. to safely call methods on a nil-able value) in 2015, with Ruby 2.3, and credits "C#, Groovy and Swift" for inspiration there. So while it isn't exactly "?" (I think Groovy does use the ?), the semantics are close enough IMO. Ref: https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/ https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-rele...
- michaelcampbell 5y agoYes, Groovy has used '?' in various forms for some years now as well: https://www.logicbig.com/tutorials/misc/groovy/safe-navigation-operator.html https://www.logicbig.com/tutorials/misc/groovy/safe-navigati... https://www.logicbig.com/tutorials/misc/groovy/elvis-operator.html https://www.logicbig.com/tutorials/misc/groovy/elvis-operato...
- scns 5y agoI think Kotlin may have had it before 2015.
- Jenk 5y agoC# added this operator in 2014 with C# 6 ( and the simultaneous release of VS2015.) https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-60 https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csh... https://docs.microsoft.com/en-us/archive/msdn-magazine/2014/october/csharp-the-new-and-improved-csharp-6-0 https://docs.microsoft.com/en-us/archive/msdn-magazine/2014/... Roslyn compiler, also supporting this operator, was released earlier in the same year, too.
- Measter 5y agoC#'s Null-Conditional operator isn't the same as Rust's Try operator. The Try operator will early return from a function, while the Null-Conditional operator conditionally executes the rest of the expression if the receiver isn't null, or else evaluates to null. The equivalent in Rust is the `and_then` method. C# also has a Null-Coalescing operator (`??`) which behaves like Rust's `unwrap_or` method.