Skip to content
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: add a builtin splice function for easier slice handling #14991

Closed
urandom opened this issue Mar 28, 2016 · 6 comments
Closed

Proposal: add a builtin splice function for easier slice handling #14991

urandom opened this issue Mar 28, 2016 · 6 comments

Comments

@urandom
Copy link

urandom commented Mar 28, 2016

This proposal is for adding a builtin splice function for adding/removing items in a slice:

splice(slice []Type, start, deleteCount int, elems ...Type) []Type

While the builtin append function can do everything that a splice function can, its a lot trickier to use for anything other than append, even by experienced go users. Newcomers to the language struggle with simple tasks of slice modification, and there are a lot of posted questions about them. It doesn't help that a function named append is supposed to be used for removing items from a slice.

On the other hand, people might be familiar with the splice function and its notation from other mainstream languages.

It doesn't seem like much, but it's a low hanging fruit that will help people new to the language.

@bradfitz
Copy link
Contributor

Regardless of its merits, the language is basically frozen at this time. Most proposals are around standard library modifications, and even then most are rejected because the standard library is also pretty frozen. The bar for language changes is high and must be supported with lots of data to support a proposal. Do you have data to support that a significant percentage of append usage is for non-append use cases?

@urandom
Copy link
Author

urandom commented Mar 28, 2016

Do you have data to support that a significant percentage of append usage is for non-append use cases?

I doubt that's true. What's true is that append is currently the only sane way of removing elements from a slice, or inserting elements at an arbitrary position.

@extemporalgenome
Copy link
Contributor

Is splicing really that common of a task? There are use-cases, but is it a day-to-day need for the average programmer working on an "average" project? Even then, is it the only solution? Splicing usually implies that the order of elements in a slice matters, thus use of the "sort" package may be an alternative to many of these needs.

Regarding the specifically proposed function signature: I'd argue that Go tends toward "i:j" semantics rather than "i:length" semantics. deleteCount is similar to "length" in this case, rather than establishing a "replacement window" that, I at least, would expect.

@bradfitz bradfitz modified the milestone: Unplanned Apr 7, 2016
@robpike
Copy link
Contributor

robpike commented Aug 1, 2016

I don't want to add more builtin functions.

@entd
Copy link

entd commented Aug 1, 2016

There is a way to add these without builtins. We all know it's name. But it
is gorbidden word around here.

2016 rugp. 1 03:49 "Rob Pike" notifications@github.com rašė:

I don't want to add more builtin functions.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#14991 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ADWPFRzEqKfZyziB9oQfkhu1U3wanpWLks5qbUKSgaJpZM4H5vZw
.

@bradfitz
Copy link
Contributor

Closing. The language is frozen.

@golang golang locked and limited conversation to collaborators Sep 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants