4 ms·
That's all fun and games if you want `foo` to be used in some `else` block but it just straightup wrong for using `foo` further down in the method as it scopes
by mdaniel 4y ago
That's all fun and games if you want `foo` to be used in some `else` block but it just straightup wrong for using `foo` further down in the method as it scopes the decl (`:=`) to the `if`
package main
import (
"fmt"
)
func Bar() (string, error) {
return "hello", nil
}
func main() {
if foo, err := Bar(); err != nil {
panic(err)
}
fmt.Printf("foo is %q", foo)
}
$ go run foo.go
./foo.go:12:8: foo declared and not used
./foo.go:15:30: undefined: foo
> In general, I've found that not catching errors is not a practical problem when writing go
Yeah, good for you, but I am obviously not a consumer of your code because I have lost track of the number of times I have to use software written by folks that try to be heroes and program using dumb editors that cheerfully don't warn about swallowing err