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

Safer slice pops #39230

Closed
mcandre opened this issue May 24, 2020 · 3 comments
Closed

Safer slice pops #39230

mcandre opened this issue May 24, 2020 · 3 comments

Comments

@mcandre
Copy link

@mcandre mcandre commented May 24, 2020

Please offer standard functions for deleting elements from a slice, instead of people using poor quality snippets from Stack Overflow.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 24, 2020

In order to add these functions in the standard library, we need generics. I don't think it's worth adding predeclared functions for these. Closing this issue in favor of generics; it can be reopened if generics is not added to the language.

In the meantime see https://golang.org/wiki/SliceTricks for possibly higher quality snippets.

@mcandre
Copy link
Author

@mcandre mcandre commented May 29, 2020

Fascinating. So append doesn't need generics, but somehow undoing appends requires generics?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 29, 2020

The predeclared append function was added to the language in 2010, when there was no prospect of adding generics to the language. Now in 2020 we are much closer to adding generics. For example, see https://blog.golang.org/why-generics. It may also be interesting to read https://www.airs.com/blog/archives/559.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.