4 ms·
> In a limited set of cases would I ever expect a result to be valid if there was also an error. You have to return something for T. Go does not allow you to
by randomdata 2y ago
> In a limited set of cases would I ever expect a result to be valid if there was also an error.
You have to return something for T. Go does not allow you to return nothing. Why would you return garbage when you can just as easily return the zero value, that of which should always be useful? Yes, you technically could return garbage, but why? There is absolutely no justification. Consider,
func GetUser() (*User, error) {
return nil, ErrNotFound
}
Here, T is useful. You don't necessarily need to look at error in this example. You can meaningfully work with T alone if the error state is insignificant to your specific use case.
What's the alternative?
func GetUser() (*User, error) {
return &User{
Name: "No User",
Email: "not@found.com",
Role: DoesNotExist,
}, ErrNotFound
}
Why on earth would you do that?
> Also, when you disagree with what someone thinks, there are different ways to respond and using "You think wrong" is probably one of the most confrontational ways of responding.
Imagine thinking that the output of software is being confrontational or exhibiting of any kind of output that congers this kind of change in "emotional state". As nonsensical as the random number generator outputting three consecutive 6s and then concluding that it must be the work of the devil. So strange.