I haven't used Go but I'm curious, how do core data structures like hash maps work without generics? Does everyone just roll their own for their particular use-case?
I'm looking forward to seeing these types of libraries improve with generics. It's notably more work to use these data structures, even if they are used rarely.
Go cheats with some built-in generic types. So you can declare a hashtable as a map of any comparable type to any other type. But yes you typically have to implement things yourself for more complex cases so that does limit the sorts of libraries that are available and the way you write programs.
The built-in types map, chan, array, and slice take type parameters, and they are usually sufficient for doing whatever you need to do.
It's incredibly great that, generally speaking, if I'm looking at Go code, the only kind of hashtable there can possibly be is the Go map data structure. The only kind of blocking queue there can possibly be is the Go chan data structure.
You will never see a LinkedTreeDeque or whatever other bizarre concoction someone might come up with. And people don't feel obligated to make every API an iterator of some kind.
Go makes being generics architecture astronautics impossible, and I really love that about it. Perhaps that makes me basic, but I am basic and happy.
meditative|5 years ago
blessed implementations inside the language, slices, maps and channels are built in generics.
sync.Map is what the standard library version looks like. It loses type safety.
https://golang.org/pkg/sync/#Map
echlebek|5 years ago
shirro|5 years ago
erik_seaberg|5 years ago
echlebek|5 years ago
It's incredibly great that, generally speaking, if I'm looking at Go code, the only kind of hashtable there can possibly be is the Go map data structure. The only kind of blocking queue there can possibly be is the Go chan data structure.
You will never see a LinkedTreeDeque or whatever other bizarre concoction someone might come up with. And people don't feel obligated to make every API an iterator of some kind.
Go makes being generics architecture astronautics impossible, and I really love that about it. Perhaps that makes me basic, but I am basic and happy.
throw_m239339|5 years ago
They are so sufficient you need to learn all these tricks by heart in order to do basic operations on slices:
https://github.com/golang/go/wiki/SliceTricks
jfkebwjsbx|5 years ago
They are not "bizarre concoctions".