3 ms·
By that definition C89 has generics too (arrays and pointers). The whole point of generics is that they are user definable. Everything else is hairsplitting.
by mseepgood 8y ago
By that definition C89 has generics too (arrays and pointers). The whole point of generics is that they are user definable. Everything else is hairsplitting.
- deleted 8y ago[deleted]
- simias 8y agoI think it's relevant in the sense that it's not particularly impressive once you know the answer. Basically the answer to the title "How the Go runtime implements maps efficiently (without generics)" is "by using compiler magic". Furthermore the article presents Go's approach superior to C++ because of the reduced code generation (since it uses a "maptype" struct for the type-specific information) but doesn't talk about the drawback of such an approach: you have additional indirections in the mapping code and the compiler can't inline and optimize for specific types. Of course in some cases that's actually desirable, very large code size can be problematic. I could also add that you could pretty easily implement Go-style hashes in C++ (actually that's often how you implement generic hashes in C, using helper functions depending on the type) but you can't implement C++-style hashes in Go without hacking the compiler or using codegen.
- hoppelhase 8y agoC11 got user defined generics, FYI. https://en.cppreference.com/w/c/language/generic https://en.cppreference.com/w/c/language/generic
- leshow 8y agoThis is something else. C++ has had parametric polymorphism in the form of template metaprogramming for a long time (the article on hashmaps even covers it). This is one of the reasons I don't really like the name 'generics', it's a little ambiguous.
- pjmlp 8y agoIt was the term coined by CLU, Ada, Modula-3, so it is already widely used in the academia.
- gameswithgo 8y agoYes, exactly correct. But nonetheless the way Go makes maps efficient is it has generics for maps.