3 ms·
Been programming in C++ for 25+ years and I could say the complexity exploded after C++11 with the introduction of rvalue references. The template syntax could
by kanbankaren 2y ago
Been programming in C++ for 25+ years and I could say the complexity exploded after C++11 with the introduction of rvalue references. The template syntax could have been simplified, but you get used to it.
People should use more typedef to make C/C++ look sane, but there is some pushback that it hinders readability, but I feel that it is the opposite.
- jprete 2y agoRvalue references et al are a valuable addition to the language if you're trying to avoid gratuitous copying. The performant alternative is a messy variety of functions that have the same effect as move semantics, except with ad hoc (or no!) compile-time checking. Using them correctly does requires a lot more background knowledge and conscious decision-making from the user than the rest of the language. Templates are not that bad as a user, but as a template author, they're a completely different programming language that makes it much harder to express even simple ideas. (Concepts may have changed that, but I haven't had a chance to use them.)
- whiterknight 2y agoThe solution for move semantics before was specializing the swap function for container types. This was a much more pragmatic approach
- fsloth 2y ago”Templates are not that bad as a user” My take would be they are bad for both users and authors. In 2024 the expected compiler output for a syntax error in a statically typed language is a specific-as-possible report where in the written source the syntax fails - not 40 lines of illegible template error messages. There are some cases where templates are the best design option. But they should be used only as the last resort when it’s obvious that’s the best way.
- pjmlp 2y agoIn 2024, I expect people implementing templates making use of concepts, and if not possible, at very least static_assert alongside enable_if. Naturally reality often times doesn't match expectations.
- MathMonkeyMan 2y agoThe problem with typedefs is that you have to find the definition. A compiler-aware IDE can help with this, but I keep cycling through intellisense, clangd, etc. and they only work if you configure things just right -- not good for reading through some unfamiliar code. Consistent naming conventions help a lot, but then that just introduces assumptions that could be wrong. As with most points of code style, it comes down to taste.
- whiterknight 2y agoI absolutely agree. Move semantics exploded the language.
- cpeterso 2y agoGotcha covered: someone wrote a 264-page book about C++ move semantics. https://www.amazon.com/Move-Semantics-Complete-Guide-First/dp/3967309002/ https://www.amazon.com/Move-Semantics-Complete-Guide-First/d...