Will Rust soon replace C++?

Rust vs C++: Who will win the race for memory-safe programming?

C++ has dominated the programming world for decades, but Rust is gaining ground. Find out why Rust is considered the memory-safe alternative to C++ and what challenges both languages present.

06.06.2024Text: bbv0 Comments
Eine Rennstrecke mit zwei Motorradfahren im Vordergrund, die sich ein Duell liefern, und weiteren Fahrern im Hintergrund

Memory leaks and buffer overflows: C and C++ have always been good at poor memory management. Unfortunately, these errors often lead to security vulnerabilities – and lots of them at that: Microsoft and Google estimate that 70 percent of their security vulnerabilities can be traced back to memory management issues.

This is no different for other companies, and has been the case for years.

Rust: The solution for memory-safe programming?

So something should be done. And has been too. What programming languages haven’t already been invented to get the better of C and C++? But this just never really worked: Either the programming language needed a garbage collector, making it unusable for real-time applications. Or it left it out and therefore had the same memory management issues as C and C++.

But Rust now solves both: memory-safe and fast, and without garbage collection. The reason for this is a special type system: The compiler ensures that the programmer does not inadvertently insert pointers to nowhere. The result: significantly less time spent debugging.

For newcomers to Rust, this also means: Rust not only prevents memory errors, but also the originally desired functionality at the same time. It’s a steep learning curve until it finally compiles.

C++ and memory-safe programming: Is that even possible?

Memory-safe management is also possible with C++: If you use a new standard, observe the CPP Core Guidelines and make copious use of compiler’s warning flags, you will most likely no longer have any memory errors.

The C++ world provides several tools to support this: Valgrind, clang-tidy, clang-sanitizer and many more. They help to find problems automatically, whereas Rust programmers have to wrestle with their compiler on their own.

The most important advantages of Rust and C/C++

Advantages of Rust Advantages of C/C++
Compiler enforces memory-safe code C++ allows a variety of programming paradigms
The compiler alone prevents bad practices Extensive warning flags and tools like clang-tidy
Some native frameworks. The Interop Initiative extends Rust access to C++ libraries Whatever is available, is also available for C and C++
Few legacy requirements Backwards compatible to the 1970s
Modern programming language C++ is constantly evolving
Young developers are interested in Rust Developers with professional experience

 

The future: Will Rust replace C++?

You can safely manage memory with C++. However, the experience with 70 percent of security vulnerabilities shows that you might be as well to leave it alone. Well-known companies and software projects are therefore switching to Rust or at least making an API available for it. The US government is even urging developers to ditch C and C++ completely.

So things aren’t looking good for C++, but will Rust actually be the replacement or just the next unsuccessful attempt to dethrone C++? My conclusion: Rust is superior to C, but a Rust compiler is not available for all platforms.

From a technical perspective, there is currently no clear winner compared to C++. Rust will probably fail because of a hang-up with recruiting personnel: at least three years of professional experience. But from where?

Embedded Computing Conference on 28 May 2024

Will Rust soon replace C++ or will it remain an unsuccessful attempt? I plan to ask listeners this question at the Embedded Computing Conference (ECC), which is taking place on 28 May 2024 at 11:30 am in Stream 2. You are most welcome to discuss this with my colleagues and me at the bbv Software Services booth.

Author

Martin König

Martin König is a senior software engineer for embedded software in the field of industrial and medical technology. His work focuses on secure and low-maintenance architecture and programming. He has a strong interest in proper documentation – for some time now also using generative artificial intelligence.

People at bbv

“Good ideas are our raw material”

Agile Software Development

Attention!

Sorry, so far we got only content in German for this section.