Since the birth of Go it's been impossible for many years to create something like a thread-safe reusable hashmap[1], which is pretty annoying when all your code is multi-threaded in goroutines. And creating such hashmap was impossible due to the lack of generics. If you wanted to build your own concurrent hashmap, you had basically 3 bad options :
- you use `interface{}`, which is bad because of the dynamics dispatch (slow)[2] and it's also not type-safe.
- you use code generation, which is bad because I haven't left the JavaScript world to start using babel for Go …
- you create a specialized hashmap for every type you need, this basically means copy-pasting the same piece of code ever and ever and changing the type signatures, which is error prone and a hassle to maintain.
[1] this is eventually gonna get better in the next release, since a concurrent hashmap will be included in `sync`.
[2] an illustration of the performance problem with dynamic dispatch can be found here : https://github.com/nieksand/sortgenerics
That said your third approach (make custom concrete types as required) has not been a huge problem for me in practice, and is probably the best choice for now.
Was generics your only problem with Go?