|
|
|
|
|
by RVuRnvbM2e
189 days ago
|
|
> There's also no way to shrink the memory underlying a slice. Sorry, that is incorrect: https://pkg.go.dev/slices#Clip > It's a common newbie mistake to think they do work like that, and write "append(s, ...)" instead of "s = append(s, ...)". It might even randomly work a lot of the time. "append(s, ...)" without the assignment doesn't even compile. So your entire post seems like a strawman? https://go.dev/play/p/icdOMl8A9ja > So (generalizing) Go won't implement a feature that makes mistakes harder, if it makes the language more complicated No, I think it is more that the compromise of complicating the language that is always made when adding features is carefully weighed in Go. Less so in other languages. |
|
Clipping doesn't seem to automatically move the data, so while it does mean appending will reallocate, it doesn't actually shrink the underlying array, right?