4 ms·
"The resulting code is actually more bloated than the copy-pasted version" How is that possible?
by protomolecule 5y ago
"The resulting code is actually more bloated than the copy-pasted version"
How is that possible?
- turminal 5y agoMore bloated != more lines of code
- protomolecule 5y agoUnless you mean 'More complicated != more lines of code' I don't understand you.
- ChrisLomont 5y agoTemplates expand, and can generate arbitrary amounts of code. If you, as a developer, don't see what happens, then you might miss it. Templates can also expand on each type they use, or combination of types, generating much more code, when non-template solutions could have avoided it. Of course, templates could avoid it too, but they're much harder to write and see how they expand. That said, templates also allow making code shorter and cleaner. So some people, once bitten by bad templates or bad usage, complain without learning how to use them. Yet another C++ ocean of complexity :)
- praptak 5y agoIt is possible with every kind of de-duplicating copy-pasted code. You need some boilerplate for the common template (not necessarily in the C++ sense), then some more boilerplate for its instantiations to replace the previously-copypasted blocks of code. Then the blocks weren't exactly identical, so the template (again, not necessarily C++) needs to gain placeholders/ifs and the instantiations need to fill them/provide conditions. If you do it with C++ templates using the traits machinery, it generates quite a lot of bloat. It is not a reason to never use these mechanisms, just to be wary of the costs.
- protomolecule 5y ago"If you do it with C++ templates using the traits machinery, it generates quite a lot of bloat. " That's exactly the part that I don't understand. How does using traits machinery generate more bloat than some other way to de-duplicate the same code? And what kind of bloat do you have in mind -- source code or binary?