4 ms·
Come on... removing an item from a list requires tricks ?? That's not a list, it is a slice. Which is a slight abstraction over an array. You the programmer
by ansible 12y ago
Come on... removing an item from a list requires tricks ??
That's not a list, it is a slice. Which is a slight abstraction over an array. You the programmer are directly responsible for the size of the slice storage, and how many elements it currently contains.
I know go aims at being memory efficient, but delete(list,obj) should be idiomatic.
If this ends up being a common operation, I could understand arguments to add it to the language. But in general if you are adding / removing items a lot, you'd be better off using an actual list data structure instead.
- bsaul 12y agoThen i guess we're back to generics. Having to use this interface : http://golang.org/pkg/container/list/ http://golang.org/pkg/container/list/ , with its "Element" wrapping a "Value" property of type interface{} seems really weird for such a basic need. It means that whenever you're storing an object into the list, you need to remember the element in addition to the original object to be able to remove it later...
- NateDad 12y agoExcept that no one ever actually used that package. We just use normal slices which are generic.
- bsaul 12y agoHence my point... People use arrays like they would use ArrayList or Vector or any dynamic container created in the last 25 years and expect to be able to remove an object in one function call.
- NateDad 12y agoAnd people use lists like they would an array and assume a list of 100 int64s uses 800 bytes, when it actually probably uses twice that much (if you're lucky).