2 ms·
So far as I am aware the only language where I've read Generics have ever "considered harmful" is C++'s Templates, which are not exactly Generics as most other
by WorldMaker 8y ago
So far as I am aware the only language where I've read Generics have ever "considered harmful" is C++'s Templates, which are not exactly Generics as most other languages use them. Generics in Java, Typescript, C# are closer in spirit to functional programming's Algebraic Data Types applied to OOP, whereas C++ Templates are much more of a macro language than that. (C++ templates have been provably Turing complete as an embedded language.) Most of the C++ "considered harmful" reasons for eschewing the Template mini-language don't apply to Generics in the other languages.
(It also seems like modern C++ developers have more come to terms with Templates, and a lot of the recent features in that language expect/are built upon Templates.)
- nf05papsjfVbc 8y agoTo be honest, I don't know where this comes from. It is of course possible to do what many would call "overly clever" things with templates in C++. However, in modern C++, even the unappealing syntax is mostly hidden and it is such a pleasure to use the standard library or to build something like it. C++ strongly subscribes to the principle of "if you don't need/use it, you should not pay for it" (in terms of performance). Given that and the constraint of backward compatibility, it does a pretty solid job of providing a kind of generics for a systems language. If those constraints do not apply to someone, they may perhaps be able to find something else which suits their needs better. I do concede, however, that it is a real struggle to learn enough C++ to get comfortable with it and not feel like there are too many booby-traps for one to feel safe with it. So, whenever people ask me if they should learn C++, I discourage them unless they are going to need it for their job, or they intend to go into game development, finance or some such thing. Anyway, I think I've begun to ramble. If you'd like to try and see the thought process behind how C++ came to be what it is, "The Design and Evolution of C++" is an _excellent_ read and I couldn't recommend it highly enough.