TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Prefer Rust to C/C++ for new code

13 pointsby ireflectover 5 years ago

3 comments

axilmarover 5 years ago
While it&#x27;s certainly possible to introduce huge memory safety issues in C++, those usually stem from using C++ as C, i.e. directly allocating and freeing memory, or using plain integers as index variables, or messing with raw pointers etc. C++ contains the tools to minimize (but not entirely eliminate) those potentially difficult to make correct operations. The problem is the defaults are not those safe alternatives, and, especially in large teams, some one some how will use C++ as C eventually.<p>C++ is used in a lot of closed systems (i.e. closed as in &#x27;no chance to communicate with outside code), as in embedded software, weapon systems, etc, so the potential of exploitation of bugs from the outside is very small.<p>Where does this leave Rust? well, if the extra safety is justified by the cost of the change, then Rust is the right choice there. But the cost of change can be really huge, because it&#x27;s not only the retraining of the developers, but also the tools, the infrastructure, the ecosystem etc. And these can be potentially very expensive to change.<p>Also, C++ is not used alone in systems where increased safety is required. There are lots of tools that can be applied to C++ code to statically discover potential bugs. The combination of idiomatic C++ and of those tools can be cheaper than migrating to Rust and the result could be of the same quality, i.e. bug-free code.<p>In conclusion, using Rust shall be judged, as always, in economic terms: between C++&#x2F;safety analysis tools and Rust, which one is the cheaper in the short term and long term? that&#x27;s the question to answer.
_slyoover 5 years ago
&gt; Your C&#x2F;C++ programmers are likely not as well-trained as you think they are.<p>&gt; The list of people who can write C&#x2F;C++ correctly, under pressure, and then keep it correct under maintenance, is very short.<p>I see this assertion with increasing frequency lately. What if this list is not really as short as you think it is? People have been writing and maintaining massive C and C++ codebases all over the world for decades. These are wildly _successful_ languages.<p>Rust is a great language, and I&#x27;m happy to witness its rise in popularity.<p>If I&#x27;m being completely honest with myself, I love C++ for its razor&#x27;s edge. Every piece of code can be _interesting_ (but normally shouldn&#x27;t be, of course). The line between brilliance and insanity is fine, and exhilarating.<p>Is good software necessarily boring? Probably. Would the world be a better place if C++ were replaced with Rust tomorrow? Probably.<p>If I&#x27;m already competent in the exciting language, and there are plenty of places willing to pay me to write it, why should I switch to the boring language? Am I the only one who feels this way?<p>Maybe I should go learn Perl.
评论 #21557297 未加载
评论 #21609503 未加载
ncmncmover 5 years ago
There is no such language as C&#x2F;C++.<p>The characteristics, best practices in, and pitfalls of C are fundamentally different than for C++. Anything that pretends to offer useful advice, but equates them, is certain to be deeply flawed. As, indeed, is TFA.
评论 #21550798 未加载
评论 #21550168 未加载