5 ms·
That's elaborate. More elaborate than expected for Go. I was expecting something more like explicit parameterized types. Go already has those - maps and channe
by Animats 8y ago
That's elaborate. More elaborate than expected for Go.
I was expecting something more like explicit parameterized types. Go already has those - maps and channels are parameterized types. You just can't define new parameterized types. Extending Go to allow those would be a smaller step. That doesn't get you overloaded functions, though.
The designers of this wanted the ability to define a new function F(T x) which works for any T upon which a known list of functions can be applied. Then they wanted that to work for separate compilation. So there's all that "contract" stuff to carry the info about what F needs from T. Seems clunky. It violates the rule "You should never have to tell the computer something it already knows." It's clear how the constraints they set upon themselves lead there, but it's still clunky.
This design does not support template metaprogramming or any other form of compile-time programming.
Whew! That's a relief.
"We expect that most people will not write generic code themselves, but many people are likely to write packages that use generic code written by others."
In other words, maybe it is a little too complicated.
- cbolton 8y agoIt violates the rule "You should never have to tell the computer something it already knows." Not really: the contract is an explicit list of requirements with API compatibility guarantees for future versions. The computer cannot guess that from the current implementation.