by 3d3mon · 13y ago · 0 comments
Another common complaint with null references is that there is no compile-time type safety that you get with option types. The go team could mitigate this by having the compiler check for possible null references that may not have been caught and emit warnings or refuse to compile.
Well, the Go code I see doesn't look like this, so that can't be right.
For instance,
s, err := server.New()
if err != nil {
// handle error
}
s.Foo()
You're not going to check that s != nil before calling s.Foo, even though s is probably a *server.Server and could be nil. But it won't be, if the New function is correct. Yes, the compiler doesn't guarantee that New gives you a non-nil pointer, but it also doesn't guarantee a lot of things about the behavior of the program.