3 ms·
I disagree. I think there are tons of people who won’t touch Go because they can’t fathom programming without generics. I think lots of people will use the lang
by throwaway894345 7y ago
I disagree. I think there are tons of people who won’t touch Go because they can’t fathom programming without generics. I think lots of people will use the language and interact with lots of existing code and realize how far one can go with respect to type safety without ever touching generics. Unfortunately, I’m also afraid that this sea of newcomers will bring all of their paradigms to the Go ecosystem which is made possible by generics, and frankly the consistency that makes Go so productive will be lost. I like generics, but I’m afraid of the cost.
- erik_seaberg 7y agoMy favorite example is https://golang.org/pkg/sync/#Map https://golang.org/pkg/sync/#Map, which should have been a typesafe drop-in replacement for map[K]V, but that isn't possible even within the standard library.
- throwaway894345 7y agoYeah, I tend not to write or use these data structures. If I want a concurrent map, I usually write my own anyway. It’s easier to add the locks I want than to keep track of how sync.Map thinks about locking a map. I understand that this attitude angers a lot of people who believe that everything should be as DRY as possible, but this way works better for me.
- vardump 7y agoI don't know about sync.Map, but many concurrent maps don't require any locking (or require rarely). Protecting map with a lock is a very naive solution, it'll perform badly with a lot of concurrent writes.
- erik_seaberg 7y agohttps://golang.org/src/sync/map.go https://golang.org/src/sync/map.go is not completely lock-free but yeah, I think it's trying to batch structural changes to the map (and atomic compare-and-set on existing entries) which isn't something I would rewrite casually. There's just no good reason that you can't reuse it without rewriting all call sites. []T and map[K]V and chan T should implement interfaces, everyone should always use those interfaces, and monomorphization should skip the runtime dispatch.