3 ms·
This is absolutely not best practice. It's perfectly idiomatic to insert an item into a slice (without the copy shenanigans you describe). The slice will manage
by weberc2 7y ago
This is absolutely not best practice. It's perfectly idiomatic to insert an item into a slice (without the copy shenanigans you describe). The slice will manage the copy if necessary.
- hundt 7y agoThat's fine as long as you don't mind if the underlying array is modified. As the parent points out, a slice is a view into an array and there could be other views into the same array. https://play.golang.org/p/goL1JtapY7q https://play.golang.org/p/goL1JtapY7q