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.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-WP2ZZQzRfwdhC30MxUMGz9QYfgOgtUYFYj16OW1qcyNw%40mail.gmail.com.

Reply via email to