r/cpp • • Jul 13 '22

Why does Linus hate C++ ?

308 Upvotes

436 comments sorted by

View all comments

Show parent comments

27

u/delta_p_delta_x Jul 13 '22

heavy use of template metaprogramming, which can easily create super bloated binaries.

I was under the impression that heavy template metaprogramming only causes skyrocketing compile times, not bloated binaries...

3

u/HabemusAdDomino Jul 13 '22

Think it through. Template metaprogramming is templates. C++ templates generate code at compile-time. Code that goes into your binaries.

14

u/delta_p_delta_x Jul 13 '22

I agree with that, but I was thinking more along the lines of... some complex recursive template specialisation that takes ages to compile, but when it eventually does, it coughs up barely a handful of lines of assembly that map to the metaprogramming recursion, anyway.

I was also certain that templates are only instantiated for the types you specify to them, unlike Java generics, so one could have a templated header but no instantiations whatsoever...

-3

u/HabemusAdDomino Jul 13 '22

... But then, there's also the rub. Every time you do instantiate the template, even conditionally, you get more code. It's both the best and worst part of C++ templates.

→ More replies (3)