4 ms·
> I see generics as adding a complexity to a type system in order to get around the limitations of the type system. that is a truism, so I assume you mean "ne
by riffraff 14y ago
> I see generics as adding a complexity to a type system in order to get around the limitations of the type system.
that is a truism, so I assume you mean "needless complexity".
You can do without generics, as pre-generics java did.
The problem is you end up with a lot of type casts (e.g. cause you can't get something out of a container method that isn't typed "Object"), more run time errors, worse tool support.
Generics aren't that hard or verbose for 90% of the cases, so it's a trade off worth making, imvho.
- SideburnsOfDoom 14y ago> I assume you mean "needless complexity". It's useful, needed complexity, if your language is strongly typed to start off with. Which JavaScript is not. Of course all complexity comes with cost, and the costs multiply, (a new feature of the type system interacts with all the existing features) even if the complexity is needed it becomes harder to use and understand the more features are added. JavaScript does away with all of that. It has loads of other flaws, but the basic design philosophy is not one that suggests the addition of generics to improve the language.
- asolove 14y agoSo if you don't want any static typing, don't use TypeScript. But if you are adopting TypeScript to retrofit some kind of static typing onto your code, and if you use any kind of functional programming helpers (map, reduce, filter, etc.) then generics are basically a necessity. Otherwise you have two options: define separate methods for mapArrayOfNumbers, mapArrayOfStrings, etc. or have a lot of casts to the ground type and write a lot of code that isn't actually statically typed.