4 ms·
In many cases, you don’t really need to check pointers unless you specifically want to handle the nil case. Go’s panic / recover feature lets you “catch” nil po
by 4death4 3y ago
In many cases, you don’t really need to check pointers unless you specifically want to handle the nil case. Go’s panic / recover feature lets you “catch” nil pointer access elsewhere. For instance, if you have an HTTP handler, it’s way easy to install a middleware that recovers from panics than it is to check for nil everywhere.
- realharo 3y agoThe point of having it in the type system is not just to force you to check it. It is also to clearly document where you need to check it, and just as important, where you don't. Without it, you don't have that "this is guaranteed to exist at this point" indication that can actually reduce the overall number of checks in practice.
- 4death4 3y agoI get what you’re saying, but it just rarely turns out to be an issue in Go. Not sure why.