Hacker News new | ask | show | jobs
by valyala 1227 days ago
Agreed with most arguments.

A few remarks:

> Like strings.Index is an easy loop to write, but it comes up so often

Actually, strings.Index() is very non-trivial function partially written in assembly in order to achieve high performance [1]. This function is used in Go projects *much more frequently* than functions from the golang.org/x/exp/maps package.

> strings.Cut is basically just an if-statement

No, strings.Cut() has non-trivial code when comparing to a trivial loop for map copy or for map delete [2].

> It’s also true that maps.Keys and maps.Values allocate slices, and that you could avoid this with a loop, but strings.Split, bytes.Split, regexp.FindAll, os.ReadDir return slices and are still worthwhile as opposed to specialized iterators for each one.

The *key* difference between maps.{Key,Value} and the mentioned functions from the standard library is that it is trivial to write the `for k, v := range m` instead of maps.{Key,Value} and avoid memory allocations, while it isn't trivial to write the corresponding code without memory allocations, which substitutes strings.Split() or other mentioned functions from the standard library.

[1] https://github.com/golang/go/blob/86c4b0a6ec70b07ab49d3813a5...

[2] https://github.com/golang/go/blob/86c4b0a6ec70b07ab49d3813a5...