4 ms·
I always felt like templates were a kludge. Clearly the libraries make great use of them, but I've never been able to implement them in a way that doesn't scre
by quantumhobbit 15y ago
I always felt like templates were a kludge. Clearly the libraries make great use of them, but I've never been able to implement them in a way that doesn't screw up the build process. Probably because I never learned them the right way. That would be the tutorial I'd like to read: "Learn C++ templates as though they aren't voodoo."
- angelortega 15y agoI agree absolutely: templates are only just a little less crappy than preprocessor magic. I personally never use them.
- exDM69 15y agoYou're very wrong. C++ templates are very capable of expressing very powerful idioms. C++11 adds this to this power with variadic templates. std::function, std::tuple, etc are the future. Please do not be offended, but if that is your attitude towards a major language feature of C++, you probably should not be writing tutorials about it.
- AshleysBrain 15y agoI disagree, templates in C++ are great! Just make sure you declare all the code (both declarations and definitions) in a header file, and it should work fine.
- quantumhobbit 15y agoHaving to put both declarations and definitions in the same header file is what feels kludgey to me. It is a break with the normal way of doing things.
- cageface 15y agoIn C++11 you can split the declaration and implementation with the new external template feature.
- cageface 15y agoThe ideas behind templates are brilliant but, yes, as implemented in an already big & complex language they seem like a kludge. But if you designed a low-level systems language from scratch with clean generics as a top priority I think you could come up with something pretty interesting and a lot simpler than the OO mismash you tend to get with C++. Think of something like OCaml but with a less intrusive runtime, for instance. C++ got a lot more functional with C++11 but there's too much baggage for the simpler statically polymorphic language inside C++ to emerge cleanly.