4 ms·
C++ templates are an inscrutable nightmare, the reputation is deserved. Rust is a bit different. Any software engineer that doesn't have a love/hate relationsh
by jandrewrogers 4y ago
C++ templates are an inscrutable nightmare, the reputation is deserved. Rust is a bit different.
Any software engineer that doesn't have a love/hate relationship with C++ templates is lying. On one hand they are extremely opaque and not user friendly, unnecessarily so. On the other hand, mastery of that dark art allows metaprogramming that you could only dream of in other systems languages -- the modern C++ template facility is extremely powerful. The number of C++ software engineers that achieve this level of metaprogramming mastery is quite small. In fairness, the C++ language has been intentionally evolving to make metaprogramming much easier than it used to be, and it has made massive strides in that direction.
Rust lacks the expressiveness of C++ template metaprogramming facilities in significant ways. However, it is plausible that it will gain them eventually. The question is if it is possible to support advanced metaprogramming without the train wreck that is C++. I think it is eminently possible to do better, the question is how long it will take other systems languages to have metaprogramming expressiveness similar to current incarnations of C++.
- newuser46547 4y ago>mastery of that dark art allows metaprogramming that you could only dream of in other systems languages Can you give an example for this?
- ainiriand 4y agoUnreal Engine vs Unity. Unreal Engine has a visual editor that allows the developers to accomplish most task without the need of entering the code editor thanks to a visual scripting language, it mirrors the C++ counterpart 100%. I believe it is not possible to do that in C# (Unity language).
- pjmlp 4y agoUnity is in the process of achieving parity via Unity Visual Scripting.
- zozbot234 4y agoRust supports compile-time metaprogramming via macros.
- pjmlp 4y agoTrue until C++17. With C++17, if constexpr, static_assert and type traits provide some tools to make life better, C++20 concepts improve on that front. Rust macros curently are harder to debug than what for example Visual C++ offers for template debugging. We are back to primitive expand macro, like in the early Lisp days.
- sundarurfriend 4y agoIs there a tutorial-style (or anything beginner-focused) resource for learning modern C++ that you could recommend? A lot of the learning material is about earlier versions (for understandable reasons), or at least don't seem to reflect C++ as it is today, and the best practices of writing code with the tools it provides.
- erk__ 4y agoI would argue that the meta-programming facilities that are in Rust are more expressive and can be used to implement things that are not possible in C++. For example embedded dsl and similar. There is likely some cases where templates can express something that cannot be expressed with generics though.