Re:Google’s Go Style Guide
by masklinn on Friday November 18, 2022 @11:32AM
(#33657157)
That rule is not without its issues when pointers get involved, due to the typed nil problem.
[ Parent
| on HN ]
Yeah, this is a setup for hard to understand bugs unless you have a corresponding rule (imposed by a linter) that a concrete type cannot be cast into an interface and then checked against nil (mostly this means when returning a concrete type from a function it should be assigned to a freshly declared variable rather than re-using a variable that could already have an interface type.
Re:Google’s Go Style Guide
by Ferret7446 on Saturday November 19, 2022 @04:48AM
(#33668674)
In practice this never happens unless you're violating other critical best practices like explicitly ignoring errors from constructors and trying to use the (nil) returned value anyway.
I think it doesn’t happen for errors because the error interface is almost always what is returned. It doesn’t seem that hard across if this style guide were followed: https://news.ycombinator.com/item?id=33566422
Re:Google’s Go Style Guide
by Ferret7446 on Saturday November 19, 2022 @04:45AM
(#33668648)
Typed nil isn't a problem, it indicates a crucial lack of understanding about interfaces, which should be resolved with education, not restricting good API design.