News for hackers. Stuff that matters.
Re:Alan Donovan and Brian Kernighan Answer Questions on Go by whateveracct on Friday November 20, 2015 @03:00PM (#10603452)
You created a playground that intentionally avoids the nil ptr dereference.

https://play.golang.org/p/Cu4sE829ZZ

Re:Alan Donovan and Brian Kernighan Answer Questions on Go by jerf on Friday November 20, 2015 @04:11PM (#10603907)
You can actually create meaningful implementations of methods on nil pointers.

    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.