On Fri, Feb 5, 2021 at 3:46 PM Fernando Meyer <
f...@pobox.com> wrote:
> I understand the pragmatism behind having or not features in the language and its standard library. But, almost all the golang projects I've worked with implement their own utility function to remove elements from a slice, sometimes with order in place, others not. Mostly always these home-brewed libraries ignore bounds-checking introducing runtime problems if the user is not careful enough.
>
> That said, when a feature becomes a ubiquitous necessity across so many codebases, I believe it should be considered to have a standard implementation.
There are two incompatible algorithms for removing an element from a
slice. One moves any remaining elements down, the other moves only the
last element in the place of the removed one.
Which one is the "standard implementation" and why?
The next question will be, why limit ourselves to removing always only
one element, why not generalize to N elements?
The next question will be, do we need to zero the now unused portion
of the slice? It matters sometimes a lot, but it's just overhead where
it does not.