Re:A brief guide to C++ template metaprogramming
by gpderetta on Sunday September 25, 2016 @04:44PM
(#12577322)
I'm quite fluent in both template metaprogramming and preprocessor metaprogramming. The former is significantly easier to write and understand, and, most importantly, to debug.
There are some things that can't be done via templates and you have to resort to the preprocessor, but for everything else, I will choose templates.
I do agree that premature generalization, in all forms, is often the root of all evil.
Re:A brief guide to C++ template metaprogramming
by robotresearcher on Sunday September 25, 2016 @12:39PM
(#12576037)
> What templates can do are not a strict superset of what the preprocessor can do.
C++ templates are Turing complete, but the C preprocessor is not.
On the other hand, I'm the exact opposite. I hate overly complex solutions to intrinsically simple problems. I use abstractions sparingly and only when they reduce overall, not just local complexity. Sometimes moving down a level of abstraction or two will yield a better solution. Write simple code. Focus on programming and solving the problem, not metaprogramming and the metaproblem. If you're spending weeks to write (and debug!) a huge "generic solution" spanning a dozen files and several thousand lines of code which someone else could do in an hour with a few dozen lines of code in one file, I don't think that's being clever at all. I've personally experienced this, being that "someone else".
The C++ purists will probably find this repulsive, but in some cases a macro will be the far simpler solution. What templates can do are not a strict superset of what the preprocessor can do.
"All problems in computer science can be solved by another level of indirection, except those caused by too many levels of indirection."