by w8rbt · 8y ago · 0 comments
As to the minimalism in Go, I wish it came with a few more default data containers.
Sorting a map by using a slice gets old after awhile. Why can't I pick a sorted tree based map (like std::map or std:set in C++) or an un-ordered hash based map like std::unordered_set, etc.? Why do the containers have to be so minimal too?
This just leads to people rolling their own and many times, that leads to poor performance and other issues which ultimately reflect poorly on the lanaguage. I've seen more string implementations in C than I can count. Most of them were bad. I hope Go doesn't end-up being like that.
- https://github.com/timtadh/data-structures ## I wrote this one.
- https://github.com/Workiva/go-datastructures ## this one is also popular.
- https://github.com/golang/go/wiki/Projects#data-structures ## big list here.
I've written them over and over, myself. They're all bad, because the problems are nigh insurmountable:
1. C string literals don't know or care about your string package.
2. Once you step outside of the string package, you're incompatible with everything else.
3. C determinedly and resolutely devolves arrays into pointers. https://digitalmars.com/articles/b44.html
Nah, Go was careful to make that impossible. (You know exactly what I'm talking about, I'm not going to come out and say it. What one, specific thing makes rolling your own container in Go literally impossible?)
I'm not arguing against generics at all (I wish Go had it), but I'm also not sympathizing with this response.
(I'm actually guessing... This isn't my domain)
(Unless of course you do code generation...but then you're not writing Go, you're writing a program that writes in Go.)
Containers are the level 0 of generic data structures: not only is an "array" significantly less useful than an "array of T" it also leads to loss of safety (you may intend your array to be an array of int, but codegen aside there's nothing precluding a user from shoving a string in there) inefficiencies (since the type of values must be erased you need an indirection, usually a pointer) and usercode-complexity (the user needs to downcast all values to the data type they hope they are).