3 ms·
Aren't most of the points raised in the article actually solved by Rust? Doesn't Rust have a much cleaner template/metaprogramming system?
by amelius 10y ago
Aren't most of the points raised in the article actually solved by Rust? Doesn't Rust have a much cleaner template/metaprogramming system?
- Manishearth 10y agoNote that Rust's system is a generics system, and there's less metaprogramming that can be done by it. Namely, the property mentioned in the post where "So if I try to use this template with the wrong type, after a bunch of template and macro expansion the compiler will print out a cryptic error showing the templated code and the failed type substitution." does not exist in Rust, since you specify bounds in the API itself. This is both a blessing and a curse. As a blessing, it leads to very neat, clean, APIs and you never have to worry about such template expansion errors. As a curse, some of the more complex bits of C++ metaprogramming (check out what people achieve with SFINAE) are not possible. I personally think the pros outweigh the cons, but many people from the C++ world really like the power of template metaprogramming in C++. Rust is planning on offering procedural macros which address some of the use cases, but not all.
- sidlls 10y agoCleaner but far less powerful in some respects. Or perhaps, as usual, the restrictions are front-loaded. For example in Rust for some operations on a generic type you must specify the appropriate Trait in the declaration ("<T: TheTrait>"). In C++ this would be deferred until you tried to perform an operation on the type for which no valid code exists after something has been instantiated. Other than metaprogramming, Rust's implementation can provide the same functionality that templates do, in a cleaner way in my view.