3 ms·
Hi! Thanks for your thoughts :) I pretty much agree with everything you said, with the exception of defending constexpr. What follows is more ranting on conste
by pubby 13y ago
Hi! Thanks for your thoughts :)
I pretty much agree with everything you said, with the exception of defending constexpr. What follows is more ranting on constexpr and praise for templates.
> The constexpr design is taking this to heart and enforcing that the code to be purely functional.
You're falling into the common trap of confusing purity with functional. constexpr is only enforcing code to be free of side effects; it's even less functional than C.
Templates on the other hand, are functional. With templates, you get pattern matching, easy recursive data types, high order functions, and more. You can literally take Haskell code, change the syntax a bit, and end up with a complete metaprogram. That's not possible with constexpr.
Templates can work with values, but more importantly, they can work with types. Being able to actually to modify the types and code of the program is essential to metaprogramming. None of that comes with constexpr. Hell, I wouldn't even consider constexpr to be metaprogramming.
In addition, templates can actually form abstractions, even ones that aren't functional. Boost.MPL, over a decade old, emulated C++-style containers at compile time using only templates. As a personal experience, I've implemented a stack-based language akin to Forth using templates, see: http://pubby8.wordpress.com/2012/10/15/stack-based-template-metaprogramming-in-c-11/ http://pubby8.wordpress.com/2012/10/15/stack-based-template-...
Well guess what? Templates suck. They slow the compile down to a crawl, their syntax is incomprehensible, and don't get me started on their error message. The only reason to use them is because there is nothing better.
C++11 had a chance to fix this. Instead, we got constexpr.