Even beyond that is:
var foo *bar
foo.Baz()
Accidentally dereferencing a null pointer in Go is dangerously easy var foo *bar
foo.Baz()
Accidentally dereferencing a null pointer in Go is dangerously easyhttps://play.golang.org/p/cjmflMBhF7
Why not learn the language before criticizing it?
if b == nil {
fmt.Println(":)")
} else {
fmt.Println(b.emote)
}
In this case, that's useless, but that's an artifact of the chosen example. I use it every so often in places where it happens to have meaning.Go often treats nil as a legal value, which means that some of the things you might expect to crash don't, and when used idiomatically can sometimes make for shorter code. For instance, the "length" call on slices will happily take a nil and return 0, you can "append" to a nil slice and get a slice back, etc. Ultimately it's still a language with a null in it, though. There's no non-nil pointer type.