2 ms·
The big difference is that with `(T, error)` as a return type, any value on the caller side will look like a valid one (thanks to zero values). a, err := f()
by qezz 7mo ago
The big difference is that with `(T, error)` as a return type, any value on the caller side will look like a valid one (thanks to zero values).
a, err := f()
// whether you forgot to handle the `err` or not,
// the `a` carries a zero value, or some other value.
In rust it's not the case, as the `T` in `Result<T, E>` won't be constructed in case of an error.
- zimpenfish 7mo ago> "the `a` carries a zero value, or some other value." Or you could return pointers and use `nil` in the error case. Bonus is that it'll then panic if you try to use it without checking the error. (Yes, I know, it makes everything else a faff and is a silly idea.)