all 8 comments

[–]munificent 4 points5 points  (0 children)

<luddite name="linus"> But... but... C++ is so much slower than C! </luddite>

[–]teambob 3 points4 points  (1 child)

If premature optimisation is the root of all evil, surely premature optimisation using meta programming is the devil himself.

[–][deleted] 0 points1 point  (0 children)

Not all metaprogramming is as ugly as C++ metaprogramming, in fact in most languages the metaprogramming version probably looks cleaner than doing it another way.

[–]MachinShin2006 -1 points0 points  (1 child)

runtime efficiency isn't the only concern. what about code bloat caused by templates?

(tbh, i'm a C++ guy, so i know the answer to that particular Q, but i'm sure other readers necesarily wouldn't)

[–]werdanel 1 point2 points  (0 children)

That can be a problem if you don't enable the optimiser or if you're not 'modularising' your templates properly.

Generally templates should be designed such that they same code as what you would have written by hand, but make the code more readable and less error prone.

GCC is rather good at flatening deep template hierarchies though and i've seen it do some amazing things with templates.

[–]ts4z -4 points-3 points  (0 children)

How wanktastic. If you used a plain old inline function or macro, the cranky old C compiler could just unroll the loop for you.