-
Notifications
You must be signed in to change notification settings - Fork 32
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
use interface instead of *stats.Engine in httpstats #101
use interface instead of *stats.Engine in httpstats #101
Conversation
for testing, have you considered using a |
I'm with @f2prateek here. I don't think this is necessary and would set a precedent for supporting something like this for other methods on the Engine, which I don't think we should do. |
I'm using the transport wrapper for a client. The right way to use it would be to instantiate an engine and give it a
can you elaborate a little more why you think this is a bad idea? It does open the door to potentially other implementations to be used with this (sub)package and it does remove some of the coupling between |
One of the concerns is that If it helps, you can think of the setup similar to |
Got it. I look at interfaces in a different way than types. Only the consumer of engine - or a subset Engine's API - would have an interface, essentially exposing just the subset to the consumer. Thanks for the feedback! |
This is one reason yeah, you're opening the door for other implementations to be injected into this (which we'd have to support). As a general rule, library authors should avoid exporting unnecessary interfaces.
While it's true that it defines the exact signature, it doesn't define the exact behavior (and it will never have the exact same behavior, otherwise it'd be the same implementation). As a contrived example, imagine a bug report we get down the line from someone who'd implemented their own Reporter and forgotten about it but is wondering why they're not getting metrics anymore. I'll defer to @achille-roussel on whether or not he wants to merge this, but hopefully I was able to answer some of your questions. If you want it explained by someone a bit more articulate than myself, check out this blog post by jbd: https://rakyll.org/interface-pollution/ In summary, if the only reason for adding a new interface is for testing than it might not be appropriate to add that new interface as an exported type. |
Thanks @abraithwaite! I appreciate the thoughtful response! |
the only method used is
ReportAt
. This way the consumer (httpstats) is asking for a specific behavior (ReportAt
).Benefits: