Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I think it even makes sense for go purists, like you need to handle errors or get panicked.

You think wrong. Go preaches that zero values should be useful, with means in the common (T, error) scenario, T should always be useful even if there is also an error state. Worst case, you will get the zero value in return, which is still useful. This means that the caller should not need to think about the error unless it is somehow significant to the specific problem they face. They are not dependent variables.

I understand where you are coming from as in other languages it would be catastrophic to ignore errors, but that's not how Go is designed. You cannot think of it like you do other languages, for better or worse.



> T should always be useful even if there is also an error state.

I disagree with this blanket assertion. In a limited set of cases would I ever expect a result to be valid if there was also an error.

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.


> 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: