News for hackers. Stuff that matters.
Re:Google’s Go Style Guide by gregwebs on Friday November 18, 2022 @12:13PM (#33657917)
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.
Re:Google’s Go Style Guide by gregwebs on Saturday November 19, 2022 @05:28PM (#33675490)
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