News for hackers. Stuff that matters.
Re:Down the Golang Nil Rabbit Hole by Cthulhu_ on Tuesday March 30, 2021 @03:47AM (#26632114)
Oh wow, I hadn't seen that one yet. Gross, I don't want to have to check for nil receivers everywhere. I hope that's a wart that gets fixed.

In Java land at some point we were taught to never use null anywhere, instead use the null object pattern.

And in Go I'd like to extend that, never call a method on a nil receiver if you can avoid it. I think it should be up to the caller to do the nil check, IF the receiver can ever be nil.

Re:Down the Golang Nil Rabbit Hole by masklinn on Tuesday March 30, 2021 @04:03AM (#26632181)
> Oh wow, I hadn't seen that one yet. Gross, I don't want to have to check for nil receivers everywhere. I hope that's a wart that gets fixed.

Hahaha oh you sweet summer child. It's considered a feature.

And since typed nils will never get fixed despite being an actual wart (though the FAQ tells you you're holding it wrong you idiot: https://golang.org/doc/faq#nil_error) there's no chance nil receivers will get removed from the language.

Re:Down the Golang Nil Rabbit Hole by spinny on Tuesday March 30, 2021 @07:29AM (#26633339)
this is probably a consequence of the language design.

you also end up with things like this: https://play.golang.org/p/wgaLGOqFDZ9