3 ms·
> how Rust would have saved you in that case, anyone could have returned 0 for the price instead of a proper type You've missed the problem that was posed. It
by thedufer 6y ago
> how Rust would have saved you in that case, anyone could have returned 0 for the price instead of a proper type
You've missed the problem that was posed. It wasn't returning 0 to indicate an error, it was changing the error value from nil to 0. In rust that would've been a type change (from Option<int> to int). Because the context here was about how stronger type systems (like rust's) allow you to be more specific about your types, and thus many code changes that would not involve the type changing in other more weakly-type languages do cause a type change in rust.
- eshyong 6y agoExcept that in Go, you always return the error alongside the value, like this: return 0, errors.New("unable to get price") It's less elegant than Options but still, very common practice. GP's company clearly hasn't bought into Go if they're using a library that doesn't follow well-known conventions.