3 ms·
I would believe Generics are highly reusable code, you shouldn't have to write and read them often. The verbosity you lost in those few lines are earned every t
by antpls 7y ago
I would believe Generics are highly reusable code, you shouldn't have to write and read them often. The verbosity you lost in those few lines are earned every time another piece of code use them.
Also you cannot just criticize without also proposing a solution :)
- suprfnk 7y ago> Also you cannot just criticize without also proposing a solution :) Why not? There can be valid criticism without there necessarily being a better solution. That's actually the whole story of generics in Go. Countless proposals, ideas, and criticism. So far, there is no solution.
- namelosw 7y agoGenerics are highly reusable is true. But people don't read and write them often because of the language design. Most Hindley Milner typed languages like ML and Haskell by default are generic by default and it's not harder or more complex than non-generic code. Thinking of a function 'swap'. The signature should just be swap : (a, b) -> (b, a) instead of swap: <T, U>(x: (T, U)) => (U, T). The language design in most of languages which discourage people using generics. In fact, non-generic code usually introduce couplings to the argument type, making things harder to change, and violates the least power principle.
- Faark 7y agoThis works nice for something as simple as a swap. But more complicated use-cases have requirements. I want those explicitly stated rather than inferred by a compiler. Abstracting the actually used features behind names like U: String, T: Map is can keep complexity hidden. Or would you prefer the compiler to auto-generate them for you from usage? (like U: must have ChatAt(int)->Char, Length->int; T: must have put(U), get(U), Length->Int) I certainly prefer names. And those have to be declared somewhere.