-
Notifications
You must be signed in to change notification settings - Fork 58
Rename packages to improve readability. #654
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
Conversation
This fixes #651 Changes: - internal/pkgecosystem -> internal/pkgmanager - pkg/api -> pkg/api/pkgecosystem + pkg/api/analysisrun.DynamicPhase - pkg/result -> pkg/api/analysisrun - pkg/notification -> pkg/api/notification - pkg/pkgidentifier -> pkg/api/analysisrun.Key Note - this is a breaking change. Signed-off-by: Caleb Brown <[email protected]>
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.
Nice changes overall! Just a few comments here and there.
type DynamicPhase string | ||
|
||
const ( | ||
DynamicPhaseImport DynamicPhase = "import" |
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.
Can we remove the type name prefix here? We're not using it anywhere else so maybe it's worth removing it here too.
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.
I'm keen to ensure the constants are namespaced properly. If they were in a package called dynamicphase
then dynamicphase.Install
would make sense. Or if they were in a package called dynamic
then dynamic.PhaseInstall
would make sense.
But outside of that context, I think the prefix helps with readability. For example:
MyFunc(analysisrun.Install)
is less clear than
MyFunc(analysisrun.DynamicPhaseInstall)
There are more characters, but I think the code is more legible.
Go stdlib uses prefixes and suffix in this way. For example:
https://pkg.go.dev/net/http#pkg-constants (Method, Status)
https://pkg.go.dev/[email protected]#pkg-constants (Seek, Err)
https://pkg.go.dev/[email protected]#pkg-variables (IPv4, IPv6)
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.
Or if they were in a package called
dynamic
thendynamic.PhaseInstall
would make sense.
I like this alternative. Or dynamic.InstallPhase
which reads a bit more naturally. I think the same change will eventually need to be made for static analysis 'tasks'
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.
After more reflection the problem with dynamic
as a package name is that we might have pkg/api/dynamic
and internal/dynamic
(same for static
).
We could decide to never create an internal/dynamic
or use an alternatives like dynamicphase
, dynamicrun
, dynamicexec
etc.
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.
We already have internal/dynamicanalysis
and internal/staticanalysis
so I don't think we'd need internal/dynamic
and internal/static
on top of those.
So we could have internal/dynamicanalysis
, internal/staticanalysis
and pkg/.../dynamic
, pkg/.../static
.
Or, if you'd prefer the external names to be longer, we can rename the internal ones: internal/dynamic
, internal/static
and pkg/.../dynamicanalysis
, pkg/.../staticanalysis
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.
Lol, I've been thinking of dropping analysis
from the internal names entirely too, which is why I'm thinking about it.
I'm not convinced yet that DynamicPhase
should be separated from analysisrun
at this stage. A package with a single tiny data-type seems unnecessary for the time being.
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 sounds like something we can do in the future as a follow up cleanup?
Signed-off-by: Caleb Brown <[email protected]>
Do we actually need an Having an empty |
I had considered that, however, all that is in this directory is specifically about interacting with this project and its data. It is possible that we may build a useful library that is not API related (e.g. the sandbox) that we may want to make public for another project to use. In which case, we would move it into /pkg/. Changing it isn't super costly either, as only imports need to be updated. |
Signed-off-by: Caleb Brown <[email protected]>
Signed-off-by: Caleb Brown <[email protected]>
Signed-off-by: Caleb Brown <[email protected]>
Nice, I think it's cleaner without What's the motivation for introducing a new type for |
I use a type for I can't easily pass To make this process simple I wrap this in a function. Now the function could have been a regular function (e.g. |
I don't think we need to introduce a new API type just for joining a slice into a usage string. As you mentioned, this can be a regular function and kept internal to the CLI programs where the string joining in a particular format is needed. For now I think the code below (comments removed) would be minimally sufficient as an API surface. I'd also say that the
|
func RunDynamicAnalysis(pkg *pkgmanager.Pkg, sbOpts []sandbox.Option) (analysisrun.DynamicAnalysisResults, analysisrun.DynamicPhase, analysis.Status, error) { | ||
results := analysisrun.DynamicAnalysisResults{ | ||
StraceSummary: make(analysisrun.DynamicAnalysisStraceSummary), | ||
FileWrites: make(analysisrun.DynamicAnalysisFileWrites), |
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 code is an example of where I think some effort to shorten the names would be worthwhile.
I think redefining types in Go is fairly low-cost. I'm also not convinced the approach taken to display documentation for
Finally, So apart from removing the alias |
At the risk of getting into bikeshed territory, I do want to echo Max's comments a little on the Ecosystem/EcosystemSet bits. This is very clever, but it seems to me there is a bit of a cost to this in terms of code comprehension with these new types and methods getting introduced to do seemingly basic things (e.g. searching a slice, joining a slice), including all the tests needed for those. I'm also not sure how idiomatic this all is -- is this pattern common in Go? A new reader of this code may have a lot of questions trying to unpack what this The bigger problem may be consistency -- if we have |
@calebbrown fair point about |
Signed-off-by: Caleb Brown <[email protected]>
Thanks! |
PTAL. I've removed the |
Nice change! Seems good to me |
This fixes #651
Changes:
internal/pkgecosystem
->internal/pkgmanager
pkg/api
->pkg/api/pkgecosystem
+pkg/api/analysisrun.DynamicPhase
pkg/result
->pkg/api/analysisrun
pkg/notification
->pkg/api/notification
pkg/pkgidentifier
->pkg/api/analysisrun.Key
Note - this is a breaking change for the
AnalysisRunComplete
notification