-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I could not find the proverb "Accept Interfaces Return Struct in Go" here #37
Comments
I'm not a great fan of that one. It's subtle and tricky to explain compactly. And although popular, it's not often easy to apply well. Plus: Why structs? There are many other concrete types in Go. |
Then this can be "Accept Interfaces Return Concrete Types" |
I still don't favor this one. It's very hard to be clear about where it applies, and it often doesn't. |
It seems to me that one example where this does not apply is when you want to make user use a constructor function, rather than making the struct exported. If you return unexported struct, the function won't be picked up by documentation tool and returning an exported struct may lead to mis-use (e.g. constructing struct "by hand", then calling their methods, without proper initialization). This seems like a practice done with defensive programming. Accepting interfaces (or maybe defining interfaces on the receiver side) would still be worth mentioning. |
following Rob Pike's comments on go-proverbs/go-proverbs.github.io#37
following Rob Pike's comments on go-proverbs/go-proverbs.github.io#37
No description provided.
The text was updated successfully, but these errors were encountered: