2 ms·
IMHO your overall thesis of "Go and Rust are very similar here" is correct, but you're missing the largest difference, IMHO. In my mind, Go and Rust's mechanism
by steveklabnik 6y ago
IMHO your overall thesis of "Go and Rust are very similar here" is correct, but you're missing the largest difference, IMHO. In my mind, Go and Rust's mechanisms are very close, except that:
* Go returns a product type, that is, you get a value AND an error
* Rust returns a sum type, that is, you get a value OR an error
This doesn't mean one or the other is inherently better, though I do admit a strong personal bias for the Rust way. The tradeoff is basically that sum types really need generics to work well, IMHO. This means that Go can drop a lot of the other machinery Rust has that makes its system work. That's the core tradeoff.
This matters because of, for example, your first bullet point. Yes, both languages statically check their errors, but the ways in which they do so and the properties you get from said static checking are significantly (in my mind) different.
- dgb23 6y agoThank you, this is an important distinction and informs the different structural idioms of handling these cases: In Go you get a flat recipe of instructions. You find an error then exit the function somehow, usually via returning. In the subsequent blocks the soundness is sometimes only implied AKA you 'know' you handled that error before and now you can assume that the other part of your 'product type' has a certain shape but they are inherently separated types. In Rust you get matching and function expressions (often from traits) flowing through a tree. There is a type soundness to this: Each branch in isolation is a statically checked part of the whole tree. (I have personally never used an advanced IDE for Go, but I can at least imagine that a sufficiently powerful one can catch quite a few of these cases as well.)