|
|
|
|
|
by groovy2shoes
4530 days ago
|
|
The "code generation = code bloat" argument really fails when you consider that the code generated for a generic function is code that would be written by hand in the absence of generics. Compare: map f [1, 2, 3]
map g [1.0, 2.0, 3.0]
Versus: integer_map f [1, 2, 3]
double_map g [1.0, 2.0, 3.0]
In both cases, you wind up with specialized versions of map (one for Integers and one for Doubles). The benefit of the generic version is that the programmer must only implement map once, and the compiler handles specializing it for various types. Without generics, the programmer has to write the specialized version for every type he needs the function for. This creates more tedium for the programmer, and does not reduce bloat in any way.Caveat lector: Though my examples above are written in Haskell, I don't have enough knowledge of GHC internals to know whether it performs specialization this way. Nonetheless, it could be a reasonable approach for Go. |
|
[1] - http://research.swtch.com/generic