Open
Description
The standard library maps
package and its golang.org/x/exp/maps variant allowed newcomers to write code in a suboptimal way. Some examples found:
// exp maps, OSPACE(n) complexity
for _, k := range maps.Keys(m) { /*...*/ }
// standard library maps
for k := range maps.Keys(m) { /*...*/ }
// idiomatic
for k := range m { /*...*/ }
// exp maps, OSPACE(n) complexity
for _, v := range maps.Values(m) { /*...*/ }
// standard library maps
for v := range maps.Values(m) { /*...*/ }
// idiomatic
for _, v := range m { /*...*/ }
// exp maps, OSPACE(n) compexity, OTIME(n) complexity
if slices.Contains(maps.Keys(m), k) { /*...*/ }
// idiomatic
if _, ok := m[k]; ok { /*...*/ }
in one case, we also saw:
// standard library maps
for k, v := range maps.All(m) { /*...*/ }
// idiomatic
for k, v := range m { /*...*/ }
It would be nice to show warnings for:
- exp maps use, as the standard library has feature parity
- maps package use where it's not necessary, like directly in a range loop
Activity