4 ms·
I think there is a different kind of modularity which you are talking about. That a solution that brings different components together requires to know about th
by pmr_ 14y ago
I think there is a different kind of modularity which you are talking about. That a solution that brings different components together requires to know about the other components is obvious. It is about how the components can be designed as free standing modules without any direct dependencies. Of course, a better module system in C++ would be great and things are moving into this direction (clang already has a preliminary implementation of the modules spec).
It is not like the addition of templates broke C compatibility. This happened long before templates were talked about. Still, C code mostly (Yes, with tricky corners.) compiles with a C++ compiler which is great and is exactly what I would expect from a sub-set of a language. Funnily, first you complain about missing modularity due to headers and then you advocate being compatible with C, whereas exactly that feature is necessary for C compatibility.
As to the efficiency: You can actually know which problem you are trying to solve in generic programming by inspecting the properties of types and optimize according to those properties. See for example the different optimizations in standard libraries when it comes to optimizing copies to memcpy calls when called with appropriate types. There is certainly a lot of generic code that is quite efficient (see std::function which compares to native function calls or hand-written virtual function call operators, very fast vector implementations (llvm, facebook), std::thread). There is, of course, bad generic code as there is bad code in every paradigm.