News for hackers. Stuff that matters.
Re:Down the Golang Nil Rabbit Hole by throwaway894345 on Tuesday March 30, 2021 @10:06AM (#26634731)
I never really hit this bug, but I realized that was because I was very rarely using pointer receivers. I would rarely use mutable objects because I found immutability easier to deal with, and if I didn't need mutability I would prefer to pass by copy. I'm not really sure what the performance implications were. It would be an extra allocation each time I passed my value object into an interface, but I probably wasn't doing that in a tight loop anywhere anyway. Passing by copy would probably also add a bit of overhead, although my structs were rarely more than a few members, so I suspect this cost was similarly marginal. I also think it helps that my mental model of interfaces is quite accurate--when I see a nil-comparison on an interface, I intuitively understand that it's operating on the interface and not the enclosed value. None of this is to excuse the use of `nil` in Go, only that it can be mitigated to a degree.

There are no comments on this comment yet.