-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 sets.NewString from apimachinery #2909
Conversation
This replaces the use of `map[string]struct{}` with `sets.String` from K8s apimachinery. This is a nice higher-level API to replace the Go idiom, which (while clever) isn't terribly approachable by newcomers to Go.
This PR cannot be merged: expecting exactly one kind/ label Available
|
The following is the coverage report on the affected files.
|
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.
/lgtm
/approve
Thanks! 😎
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ImJasonH The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
The following is the coverage report on the affected files.
|
Honestly this doesn't seem worth it to me. Going this route and being consistent would mean we are now gonna need to be vigilant and/or add automation to see if ppl us the go based approach, and it seems like the only thing we maybe gain is ppl not needing to learn the
I don't want to die on this hill tho! |
My last 2 cents that I can't stop myself from expressing: there is something to be said for using a lang idiomatically. This feels like we are trying to make Go more similar to some other language that is more familiar to ppl, and I'd prefer we use Go idioms instead. |
@bobcatfish I tend to agree with you. And in hindsight I think this perspective would have similarly resulted in me not creating #2587. Is there something we can do to codify this approach in our docs? |
@bobcatfish Ack on most of these points, but I'll add a bit of my own color to this as well. Sorry this turned into a wall of text. 😬 Regarding the "one time cost", while I agree that there is a one-time hit to learn the idiom (vs. say This becomes especially true when the sets become elements of a larger type, e.g. Furthermore, there are gains beyond simple readability from this as well, such as having methods for walking the deduplicated ordered members: ... or should the need arise performing other "set" operations like difference and intersection. Many Go idioms like While this library may be overkill for many of the cases rewritten, I do think that it almost universally improves the readability without any material runtime cost (it is after all a type alias of the Go idiom), and I think there are instances (as above) where it eliminates one-off code. Good use of Go idioms and good use of libraries shouldn't be at odds with each other, and while I value consistency I think this is as much about educating contributors and reviewers about available libraries as it is Go idioms. I think that understanding of available libraries better prepares both sets of folks (no pun intended) to exercise good judgement about what's best for their particular situation. I too don't plan to die on this hill 😅 , so if you don't want this PR, I would be happy to roll it back, but it sounded like @imjasonh and @afrittoli thought this was a positive change (here and in |
np np! my apologies for not replying faster also
I agree. It makes me wonder: why did Go make this the idiom? If a language's idioms are too hard to understand, to me that points toward a problem with the language. Maybe we decide: we are using Go because of XYZ (I'm guessing concurrency support) however we think its idioms are inscrutable, therefore we are hiding them. I'm probably being unreasonable thinking that it's that simple, but in general what I want to do is embrace the language I'm using. If there are problems with the language, it feels like the place to deal with that is in the language itself. (maybe that's happening already...)
That's a good point, I hadn't thought that through. Maybe once Go has generics this will all be a moot point - until then it seems like the decision was made that it was okay for folks to duplicate this kinda code when they need it:
Kinda like how it's okay to have to go Maybe what really bothers me is that this code is inside of k8s api machinery, i.e. we are depending on a lib inside of k8s - fortunately we already rely on it, so maybe that makes sense. I don't know if I'd be having the same reaction if someone had written a Maybe you're right about the other functionality we get - and maybe once Go has generics this will all be moot and the Go standard libs will include more of this kind of thing.
nah that's okay - thanks for taking the time to discuss this! |
Feels like backfill to me. "Oh shoot, people want sets!" "What is the most efficient way to do this within the language?" pissing contest ensues Profit! |
The comment still described its return as a map, but in tektoncd#2909, that was changed to a `sets.String`. When I happened to stumble across this while looking into something else, I thought "hey, this should probably be updated to be accurate!" Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
The comment still described its return as a map, but in #2909, that was changed to a `sets.String`. When I happened to stumble across this while looking into something else, I thought "hey, this should probably be updated to be accurate!" Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
The comment still described its return as a map, but in tektoncd#2909, that was changed to a `sets.String`. When I happened to stumble across this while looking into something else, I thought "hey, this should probably be updated to be accurate!" Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
Changes
This replaces the use of
map[string]struct{}
withsets.String
from K8s apimachinery.This is a nice higher-level API to replace the Go idiom, which (while clever) isn't terribly approachable to folks unfamiliar with Go.
/kind cleanup
/assign @vdemeester @afrittoli @imjasonh