News for hackers. Stuff that matters.
Re:Go is not an easy language by jholloway7 on Monday February 22, 2021 @02:54AM (#26221935)
This problem transcends documentation of any given language's standard library. list.delete(value) in any programming language is a degenerate without an ordering or hash built-in to the underlying data structure.

If you ever need to delete based on value, it's a smell that a list is the wrong data structure. I'm sure there are cases in constrained environments where a linear search is heuristically okay, but generally in application development list.delete(value) is a hint that you're using the wrong data structure.

Re:Go is not an easy language by mhaymo on Monday February 22, 2021 @05:46AM (#26222998)
Good point. I guess the reason the author finds removing from lists to be relevant is because there is no Set structure in the Go standard library. They should use a `map[t]bool`, but that is non-obvious to many programmers.
Re:Go is not an easy language by dullcrisp on Monday February 22, 2021 @08:41AM (#26224356)
My Google search suggests that maps in Go aren’t ordered. If so this doesn’t work in place of an array.
Re:Go is not an easy language by vlowther on Monday February 22, 2021 @09:44AM (#26225061)
`map[t]struct{}` saves you a few bytes per entry. Just use the `_,found := foo[key]` form of lookup
Re:Go is not an easy language by simiones on Monday February 22, 2021 @02:43PM (#26229503)
Unfortunately, map[t]bool (or map[t]struct{}) only works for special structs that happen to have equality defined for them. It's not a general purpose solution, it's just a hack.
Re:Go is not an easy language by nitrix on Monday February 22, 2021 @09:46AM (#26225089)
map[t]struct{} so that the values don't require any space.