4 ms·
"Generics" (a.k.a. parametric polymorphism) might be terrible for code clarity in a verbose language with subtyping and little to no type inference, but in many
by willtim 6y ago
"Generics" (a.k.a. parametric polymorphism) might be terrible for code clarity in a verbose language with subtyping and little to no type inference, but in many languages they actually improve code clarity:
map : (A -> B) -> [A] -> [B]
It's quite clear from the above type signature what this function does and does not do. It can only use the supplied A's to create B's using the supplied function. It cannot do anything else with the A's and the B's. To me, that is clarity.
- parasubvert 6y agoThis is true. But care must be taken with the feature. Iirc, Java Generics tried to take their time but refused to adopt more (at the time) exotic type inference to simplify the syntax.