-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: bytes: add Grow, Clip; maybe add bytes/strings Insert, Delete #48594
Comments
I don't see why this functionality should be duplicated instead of deprecating/forwarding the existing api to the new slices package |
Why?
|
It seems like for now we can stick with package slices, which works perfectly fine on []byte. |
This proposal has been added to the active column of the proposals project |
The inverse proposal would be to deprecate bytes.Equal and bytes.Compare, and remove bytes.Clone before it ships. I guess that would be fine too, but I don’t think it makes sense to add Clone in 1.18 but not Grow and Clip. |
The key difference with (The order of |
Deprecate is pretty strong - it's not harming anything to keep the old functions around and working. |
Based on the discussion above, this proposal seems like a likely decline. |
The emoji reaction as of now on the initial post is 2 👍 1 👎 and 1 😕. I'm going to go ahead and close the issue for now because the underlying question is "Do users have an expectation of parity between slices and bytes/strings, as they have an expectation of parity between bytes and strings?" and we just don't know yet. Maybe after slices is released people will ask for bytes.Grow, or maybe people will be so happy with slices.Grow, it won't occur to them to go looking for bytes.Grow. We shall see. |
This proposal has been declined as retracted. |
Background:
Accepted proposal #45955 adds a new package called slices with the following API:
Of the 14 functions, package bytes already contains 5 identical functions:
Proposal:
The 4 Func variants don't really make sense for bytes, because they would involve mapping one byte to another, when it's more likely one would want to map one subslice to another. Similarly, Compact seems like a bad fit for bytes, since it would operate on sorted bytes, of which there are only 256.
That leaves 4 functions in slices but not in bytes. Of those 4, Grow and Clip seem extremely useful. I am already using them in my code, and variations of them can be found all over. I propose that they should be added to bytes for convenience and general parity with slices, since users already can find type specific versions of many slices functions in bytes and will reasonably expect to be able to use Grow and Clip as well.
The other two are Insert and Delete. These could also be useful for strings and we might want to add them to both bytes and strings packages. I am more ambivalent about adding these, since their Big O are O(len(s) + len(v)) and O(len(s)-(j-i)), but OTOH, if you know you needed them, why wouldn't you use them?
The text was updated successfully, but these errors were encountered: