2 ms·
Wow, 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
by lobster_johnson 11y ago
Wow, 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.