8 ms·
In Go you rely on convention that if err != nil, the other value is meaningless and should not be used. You have to remember to check this, and some interfaces
by progbits 3y ago
In Go you rely on convention that if err != nil, the other value is meaningless and should not be used. You have to remember to check this, and some interfaces break this convention and use eg. error+some partial value, or nil+nil or other combination.
With Rust's Result<T> you either get the value, or the error. Never both or neither. Those states are simply unrepresentable. absl::StatusOr does the same in C++, with slightly worse ergonomics.
> If there was an error, the value should be meaningless. I don't understand what your complaint is against returning both the value and the error.
Think of it this way: why are you even returning a meaningless value in the first place?