2 ms·
The ? thing, didn't that get borrow from Swift, in fact?
by cmrdporcupine 3y ago
The ? thing, didn't that get borrow from Swift, in fact?
- dgacmu 3y agoIANASE (swift expert), but the rust ? operator is used for error propragation in the same way that the try operator in swift is. Swift's ?? operator is for unwrapping an option type: x ?? default, similar to x.unwrap_or(default) in Rust. (Swift's ? is the ternary operator, as in C; rust does not have a ternary operator, using expression-if instead). Applied to a type, swift's ? is the same as Option<x> in Rust. Rust's first mechanism for error propagation was the now-deprecated try!() macro, which did basically the same thing.
- tomca32 3y agoCreator of the Rust language Graydon Hoare is working on Swift, so it’s probably the other way around
- u320 3y agoHe left Rust long before ? was introduced.
- tomca32 3y agooh fair enough. Didn't know the timing of that, so I thought it was connected.
- steveklabnik 3y agoAs far as I know, Graydon hasn’t been working on Swift for a few years now.
- masklinn 3y agoNo. For starters ? was introduced by C# 2.0 almost 10 years before Swift appeared so it would have been lifted from that if anything, but then Rust’s ? has completely different semantics than everyone else.