-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
quickfix: suggest using slices.Concat
when possible
#1552
Comments
Personally I wouldn't say that slices.Concat() is strictly better for just two slices:
Both are easy to read, and both will have the same performance. However, with three or more slices it's a different story:
Those are much harder to read. And slices.Concat will typically be faster (whether that matters is of course a different story, but in some cases it likely will). So I'd say that it should only suggest this for 3 or more slices. |
I would say using slices.Concat would somehow promote the usage and curiosity of people to look at I'm fine with saying it would be suggested only after 3 slices concatenated. But I have to say. I know the ellipsis when using append confuses some juniore or people coming from other language. |
Well, maybe, but that seems mostly a stylistic preference than anything else. And also:
And that's just my own projects; doesn't includes stuff from other projects I work on (I put those in ~/src rather than ~/code). I'm not looking forward to replacing that with something that's basically just identical. |
For the time being I would only add a quickfix that can replace both the 2-slices and n-slices cases. I agree that we don't want to flag all existing code. I also don't want to differentiate between 2 slices and 3+ slices. Improving existing code would be better suited to |
slices.Concat
when possibleslices.Concat
when possible
I'm fine with this |
golang 1.22 came with slices.Concat
we could now suggest using it instead of the good old way we had until go 1.22
append + elipsis
we can now use
The text was updated successfully, but these errors were encountered: