Hacker News new | past | comments | ask | show | jobs | submit login

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++.




True 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.


Is 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.


I 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.


>mastery of that dark art allows metaprogramming that you could only dream of in other systems languages

Can you give an example for this?


Unreal 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).


Unity is in the process of achieving parity via Unity Visual Scripting.


Rust supports compile-time metaprogramming via macros.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: