-
Notifications
You must be signed in to change notification settings - Fork 295
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
Prefactor types into a separarate types package #38
Conversation
This came up in #37 where we ended up in a dependency loop. - main package was importing a specific rate limiter type - both rate limiters needed to import Clock types from main package By moving it to a separate package we avoid that loop. If we decide to go ahead with #37, this will also be necessary to have a "common config type" that can be re-used between all N alternative limiters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to make the API worse for users (I've seen this with zap / zapcore split as well).
Is there a big advantage in moving the implementations into separate packages vs having them unexported in the same package?
In what way would it make it worse? I thought type aliasing would be invisible (?) - note we're still exporting only a single package unlike zap. As to why:
So I having a single interface/constructor options exported, and but splitting implementations would:
It wouldn't be impossible with a single package, just more messy. I was also toying with a thought of returning different implementations based on user params - that would require more testing though. For now, the mutex implementation seems to be faster for a single goroutine though, but not sure if that will hold. We could:
I'm for (1), but I guess it depends on how much worse it would
What are you concerned about? :> |
It's actually a little worse with type aliases to an internal package, since users will be forced to look at the API documentation for an internal package to understand the types fully. See how a type alias shows up in documentation: https://pkg.go.dev/go.uber.org/zap#Field There's basically no information, no method set, etc.
I understand the need for 2 implementations, the differences between them, but I don't think any of that explains why a separate package for each implementation helps. The implementations are small enough to be separate files, what advantages do we get from moving them into separate packages?
My preference is the other way around -- keep everything in a single package, and figure out workarounds for the dependency loop (which itself is actually caused by having multiple packages). |
Yeah, I understand what I'm causing;)
This I don't understand - if we keep everything in a single package, there's no loop, so there's no need for workarounds? ;)
Might get to 4-5, at least temporarily.
The usual package benefits:
All that could still be achieved in a single package, but splitting it up "is free" - I don't have to think about it, go will check for me and make sure I make no silly mistakes. |
Spoke with @prashantv directly. Agreed that type aliasing to a private package is not the way. Package splitting it's still something I'd like to think about, but that can happen in #37. |
This came up in #37 where we ended up in a dependency loop.
By moving it to a separate package we avoid that loop.
If we decide to go ahead with #37, this will also be necessary
to have a "common config type" that can be re-used between all N
alternative limiters.