3 ms·
What, specifically, do you mean when you say Rust is "awful to work with"? With C and C++ I agree, but I've had a drastically better development experience in
by mcronce 5y ago
What, specifically, do you mean when you say Rust is "awful to work with"? With C and C++ I agree, but I've had a drastically better development experience in Rust than Go.
- svnpenn 5y agoYou should probably read the rest of the comment...
- mcronce 5y agoAre Result and Option really the only thing? Because nesting scopes based on Err/None is rarely the right choice, just like nesting a scope based on `if err == nil` isn't typically something you want to do in Go, or `if errno == 0` in C - You can panic trivially with `.unwrap()` - You can propagate the condition up trivially with `?` - `?` doesn't work with all types, but it does work with Option, and it does work with the vast majority of error types - making your custom error work with it is very easy (if you're whipping up an application or prototype and want your error handling very simple, `anyhow::Error` works great here) - You can convert None to an Err condition trivially with `.ok_or()?` - In cases where it makes sense, you can trivially use a default value with `.unwrap_or_default()` And all of these use require a _lot_ less code than `if err != nil { return nil, err }` And all of these allow you to use the Ok/Some value directly in a function call, or in a method chain, while still enabling the compiler to force you to handle the Err/None case The common theme here being "trivial" :) Result/Option are a big piece of that better developer experience.
- rastignack 5y agoHowever in typical rust code bases this systematic wrapping causes a lot of unhandled panics. Reading it feels just wrong.