3 ms·
Compile-time code/type generation and verification, which leverages advanced template functionality and constexpr extensively. For applications like database en
by jandrewrogers 8y ago
Compile-time code/type generation and verification, which leverages advanced template functionality and constexpr extensively. For applications like database engines with dense, complex data structure interactions, this facility allows you to make fairly deep guarantees about correctness at compile-time that would otherwise require mountains of runtime assertions that as a practical matter programmers won't write with sufficient coverage and may not be tripped in testing in any case. If you make code/design changes, it won't compile if you've introduced one of many common bug types that are otherwise hard to detect when writing code. In my experience, these kinds of bugs are more common than memory safety bugs (which in my experience are a non-issue for modern C++).
This is fairly magical when you use it but it requires a different coding style than some systems programmers are used to. Instead of writing code, you end up writing a lot of meta-code that generates and verifies what actually gets compiled. Recent versions of C++ have invested a lot in making these facilities expressive and reasonable to use in complex software. In my experience this has substantially reduced the code defect rate and simplified testing. Once you've written a system this way, it is very hard to go back.
Not having these facilities would be a huge step backward for writing practical high-assurance/high-reliability code. AFAICT, Rust is still quite primitive in this regard.
- 0815test 8y ago> Compile-time code/type generation and verification Rust does have a procedural macro system which can be used to do these things. Surely actual procedural macros are better than hacking the template system to generate custom code, which is the typical approach in C++.
- jandrewrogers 8y agoThis is not remotely the same. You are seriously underestimating the capabilities of C++17 in this regard.
- JoachimSchipper 8y agoDo you happen to have a link to a page explaining these techniques? I code in C and dabble in Rust, but this sounds interesting. (Sorry, I know this is a few days old by now...)