3 ms·
My Go is very rusty so I was spending some time refreshing my memory on the empty interface. As I understand it, in the worst case that Go's generics are imple
by Jtsummers 6y ago
My Go is very rusty so I was spending some time refreshing my memory on the empty interface.
As I understand it, in the worst case that Go's generics are implemented with boxed types and a pretty wrapper around the empty interface, you end up with equivalent performance to today but with clearer code (within functions, function declarations becoming somewhat more complicated but not excessively so).
But in the best case, this information being given to the compiler will give you clearer code (same qualifications as previous paragraph) and better performance as run-time type verification is moved to compile-time.
I suppose if you never use the existing workaround (empty interfaces), then there's no benefit to you in having generics available. But if you do, it seems to me that you're going to get some benefit.
- lhorie 6y agoWell, I don't think the feedback of people that don't use (or, more specifically, who don't feel the pain of not having) generics is all that relevant. In my mind, the trade-off is between potential runtime performance improvements via monomorphization vs the compile time cost of figuring out how to emit said code. I also think there's an important consideration in terms of community and ecosystem. There are plenty of examples elsewhere where splitting on some core aspect of a language had some long lasting damaging effects (python 2 vs 3, perl vs raku, D v1 phobos vs tango, etc). I don't necessarily anticipate that this would be the case here, but it'd be unfortunate if the community split into different go flavors based on similar-but-incompatible ways of doing similar types of tasks.