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 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

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 commented May 29, 2020

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

@ianlancetaylor
Copy link
Contributor

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.

@golang golang locked and limited conversation to collaborators May 29, 2021
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

3 participants