3 ms·
> Question: what is the reason for the silent copy when append exceeds the original slice cap? Because Go slices play double duty as vectors. And that is the u
by masklinn 4y ago
> Question: what is the reason for the silent copy when append exceeds the original slice cap?
Because Go slices play double duty as vectors. And that is the usual behaviour of a vector.
And the issue is the opposite situation, when appending does not exceed the original slice cap. The entire point of the slice trick is to force a resize (and thus a copy) on append.
> it feels like it would be safer to throw a comp error and force the user to deal with it when a user is trying to exceed the cap of the underlying array?
It would be safer to have not confused slices and vectors, but half-adding that confusion sounds even worse, your suggestion would only keep the worst parts, and would require hand-rolling the rest every time.