3 ms·
Current compilers still generate huge binaries for code that makes excessive usage of templates; I've personally had to rip out a lot of heavily templated code
by wheels 17y ago
Current compilers still generate huge binaries for code that makes excessive usage of templates; I've personally had to rip out a lot of heavily templated code in the last year for that reason.
They also still (with the Intel compiler as a notable exception) generate nonsensical error messages when templates are used heavily.
The latter reason is one of many that a lot of C++ programmers don't do well with heavy template usage. One naturally could fault those programmers, and I think that's half-way fair, but in designing reusable APIs, API usability is and should be a concern. The corollary seems is obviously a bad principle when applied to (graphical) interfaces: if the users weren't so dumb it'd be easy to understand. I believe the same holds true, generally, for API design.
Half-way related, I'm personally quite a fan of Designing Qt-style C++ APIs:
http://doc.trolltech.com/qq/qq13-apis.html http://doc.trolltech.com/qq/qq13-apis.html
As for "modernness" the point still stands; when some people say, "modern music" they mean "avant garde". Others mean "the stuff on the radio". I mean the stuff on the radio; Alexandrescu is the avante garde.
- kingkongrevenge 17y agoCompilation speed and incomprehensible compiler errors remain an issues for template heavy code but this is the first time I've heard complaints about binary size. Can you educate? Theoretically the incomprehensible compiler errors will go away in the next couple years as compiler writers integrate C++0x "concepts."
- wheels 17y agoEvery specialization of a template creates a new instance of it with new symbols. With heavily nested templating that can add up quite quickly. The most problematic case at my last company was where there were several hundred specializations (just one-liners) one after another in some of the error handling code. Each of those specialized several more templates. I managed to shave a few dozen MB off of the binary size (and remember, larger binaries == more cache pressure) by replacing the templates with a base class and virtual function.