3 ms·
> Go basically tells us that errors are as really important — they should be in your face and handled by the caller. And then it goes ahead and makes it a secon
by pcwalton 11y ago
> Go basically tells us that errors are as really important — they should be in your face and handled by the caller. And then it goes ahead and makes it a second-class citizen that is really awfully laborious to work with. Why not make error-handling a first-class construct?
Not only that, it's very easy to just dump errors on the floor, which is why Golang needs tools like errcheck.
For an easy example of this in practice (os.Setenv returns an error): https://github.com/search?l=go&q=os.Setenv&type=Code&utf8=%E2%9C%93 https://github.com/search?l=go&q=os.Setenv&type=Code&utf8=%E...
- lobster_johnson 11y agoWow, people do this? I did have an error go unnoticed recently, but it was like this: v1, err := doStuff() if err != nil { return } var v2 MyStruct if value != nil { v2, err = doMoreStuff( some_param, different_param, one_more_params) } // ... use v1 and v2 err = doYetMoreStuff() I didn't catch the orphan err because I absent-mindedly focused on the parameter list to doMoreStuff() and just didn't see it. But I find it frustrating that Go will, on the one hand, angrily refuse to compile a program where a variable is unused, but on the other it will happily accept a program where a value is never used. Isn't that potentially as bad? I'd rather have it complain and force me to assign to _ if I really wanted to discard it.