3 ms·
That rule is not without its issues when pointers get involved, due to the typed nil problem.
by masklinn 4y ago
That rule is not without its issues when pointers get involved, due to the typed nil problem.
- gregwebs 4y agoYeah, 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.
- Ferret7446 4y agoIn 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.
- gregwebs 4y agoI 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 https://news.ycombinator.com/item?id=33566422
- Ferret7446 4y agoTyped 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.