4 ms·
> A really clean approach to handling Maybe results that Rust has exactly the same question mark syntax, and obviously V copied it from Rust. Copying good ide
by lightgreen 6y ago
> A really clean approach to handling Maybe results that
Rust has exactly the same question mark syntax, and obviously V copied it from Rust.
Copying good ideas from other languages is right.
> I haven't seen in other languages before
But you did not know that the syntax was derived from Rust. And the value of a review of some programming language from a person without basic knowledge of the space is not very helpful.
It's likely that you missed a lot of other important details. Like this one:
> V is essentially a much cleaner version of Go, syntactically
Syntactically only, yes. But it is very different from Go, because it does not do garbage collection.
Sorry.
- gavinray 6y agoAh, I meant the "or" operator, in Rust you have to match on the option result right? match maybe_error { Ok/Some(val) => None/Err => }
- hardwaregeek 6y agoYou can do result.or_else(|err| ... ) Or result.map(|value| ... )
- gavinray 6y agoAh welp, fair enough that's on me for being clueless. Edited my answer.
- edflsafoiewq 6y agoYou can do result or { break }. You can't do that from a closure.
- edflsafoiewq 6y agoV's Maybes are different than Rust's, only the ? syntax is similar 1. Option/Result are unified into a single type, ?T. 2. It is not parameterized over the error type. 3. The Ok() case does not need to be marked (ex. you write 1, not Ok(1)). 4. In addition to the x? sugar, there is also x or { ... } sugar, which is like Rust's x.unwrap_or(|err| ...) except without the closure so you can eg. break or return from the block. There is also if y := x { .. } else { ... }, which is like Rust's match x { Ok(y) => ..., Err(err) => ... }. These are all reasons you could think V has cleaner Maybe handling than other languages.
- vlang1dot0 6y ago> 1. Option/Result are unified into a single type, ?T. This is not a positive. Option<T> and Result<T, E> have semantically different meanings. This is like saying integers and strings have been unified into a single type: string.