• SilverShark@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    20 days ago

    Might be that I’m so used to the status quo, but I like the current way Go handles errors very much.

    I do understand that there is a lot of code repetition, and many lines of code in a function will go for error handling instead. But I also feel that when we don’t focus too much on happy path and do handle errors, we end up with a lot more work on it then on the happy path anyway, so the number of lines that go for error handling do correlate with the amount of effort we take there anyway.

    I think in errors, a thing that might be improved is what to return on the “normal/happy path” side when there is an error. Suppose a string that returns a string and an error. If there is no error, I get some string and nil on the error. But if there is an error, I still need to return a string (an empty one, but still). If it’s a struct being returned without being a pointer, then it still needs to be returns. Many feel this is a weird aspect about the language.