3 ms·
While this is mostly true, there are some (very limited) circumstances where modern language constructs are legitimately the best approach. Generic libraries a
by pclmulqdq 6y ago
While this is mostly true, there are some (very limited) circumstances where modern language constructs are legitimately the best approach. Generic libraries are probably the most obvious case where you may need some fancy metaprogramming. Move semantics and other similar tricks for avoiding copies are often used for saving much more than a 24-byte copy.
Unfortunately, a lot of C++ enthusiasts who write this kind of code are language lawyers who might prefer to write in APL (a language with "expressiveness" and "beauty") than a language for humans.
- whatshisface 6y agoThe C answer to generics is void pointers, careful programmers, and CVEs. CVEs are the most important C language construct.
- lmilcin 6y agohttps://insights.dice.com/2019/11/27/programming-language-vulnerabilities/ https://insights.dice.com/2019/11/27/programming-language-vu... I think this has reasonable explanation: “The high number of open source vulnerabilities in C can be explained by several factors,” the organization added in a blog posting. “For starters, C has been in use for longer than any of the other languages we researched and has the highest volume of written code. It is also one of the languages behind major infrastructure like Open SSL and the Linux kernel. This winning combination of volume and centrality explains the high number of known open source vulnerabilities in C.” So... C++ is there. That it isn't the top of the list is a reflection on the fact that it is rarely used for important stuff. Nobody registers CVEs for computer games, yet they are predominantly written in C++ and full to the brim with security holes. If what you said was true, these should fare better than C code, and yet they do not.
- whatshisface 6y agoThat's kind of a useless chart for the reason you point out, which is that it doesn't divide by language use. I think computer games are a bad example because game developers don't care about code quality for their release-once-and-done games.
- lmilcin 6y agoI strongly believe readability trumps everything when it comes to writing code for a lot of reasons. I love modern language constructs when I can use them to help make the code more readable and verifiable. What I dislike is using language features to make the code seem more intelligent and eloquent where there already exist simple, dumb, readable way to achieve same result.