Is It Too Early to Replace C/C++ with Rust?

Is It Too Early to Replace C/C++ with Rust?
Follow
Script Home
, together with millions of developers

Is It Too Early to Replace C/C++ with Rust?

Source丨51CTO Technology Stack (ID: blog51cto)

Written by丨Qianshan

If reprinted, please contact the original public account

Rust has been quite busy recently.
First, Microsoft’s CTO publicly stated: “It’s time to use Rust to replace C/C++ for creating new projects!” Then Linus Torvalds indicated that, barring any accidents, Linux 6.1 will preliminarily support Rust.
As a new language, Rust has been gaining momentum in recent years.
According to a report from developer analysis company SlashData, from 2021 to the first quarter of 2022, Rust was the fastest-growing language in terms of usage. Additionally, in the StackOverflow related survey, Rust has been the most popular programming language for several years. Moreover, tech giants like Apple, Microsoft, Google, Amazon, and Meta have gradually adopted Rust, undoubtedly accelerating the growth of the Rust ecosystem.
Seen by many as the “successor to C++,” Rust is increasingly entering people’s view. The question of whether Rust will replace C++ in the future is also gradually emerging, but the competition between old and new programming languages has always been the same; only time will bring the conclusion. For now, let’s take a look at Rust’s recent active presence, from which we might glimpse its development trajectory.
01
Google: A Roundabout Journey
Seeking a Successor to C++
From the outside, Google has always held a very open attitude towards Rust.
The recently launched open-source operating system KataOS by Google has drawn a wave of attention. Notably, with the principle of prioritizing security, KataOS is developed using Rust and is built on the seL4 microkernel. The reason for choosing Rust, according to Google, is that “it provides a strong starting point for its security, as Rust eliminates entire classes of errors, such as off-by-one errors and buffer overflows.”
In addition to using Rust for developing the new system, Google announced last year that AOSP supports using Rust for developing the Android operating system. At that time, Google engineers pointed out that memory safety bugs in C and C++ are one of the long-standing issues. Despite Google having invested significant effort and resources to detect, fix, and prevent such bugs, memory safety bugs remain the primary cause of stability issues, accounting for approximately 70% of serious security vulnerabilities in Android. Compared to the complexity of memory management in C and C++, Rust can ensure memory safety through compile-time checks (ensuring object lifetimes and ownership) and runtime checks (ensuring valid memory access). Moreover, Rust provides performance comparable to C and C++ while implementing safety.
Furthermore, in the discussions about whether to introduce Rust code into the Linux kernel, Google has publicly expressed its support. Google’s security blog stated: “We believe that Rust is now ready to join C as a practical language for implementing the kernel. It can help us reduce potential bugs and security vulnerabilities in privileged code while integrating well with the kernel, significantly retaining its performance characteristics.”
It can be said that Google has consistently supported Rust. However, in the experimental journey of finding a successor to C++, Google has not stopped at Rust.
At the CPP North C++ conference held in July this year, Google open-sourced and released a new language called Carbon, which it claims is an experimental successor to C++.
Google engineer Chandler Carruth introduced that Carbon aims to fully interoperate with existing C++ code, with the goal of making it as easy as possible to migrate from C++ to Carbon. In comparison, while Rust has clear advantages in memory safety, it may never achieve sufficient interoperability with C++ to facilitate a smooth migration.
Regarding the emergence of Carbon, Bjarne Stroustrup, the father of C++, gave a straightforward response at the invitation of the media: “There are always new languages trying to become the successors to C++. I welcome experiments with programming languages and programming styles, but I do not want to spark controversy. It is easy to criticize established languages because we know their problems, but it is often difficult to provide alternatives without creating entirely new issues in language rules, libraries, and management. Carbon is too new and lacks sufficient specifications for me to make meaningful technical comments.”
02
Microsoft Azure: CTO Supports Rust
Battle with the Father of C++
Similarly supportive, compared to Google’s attitude towards Rust, Microsoft appears much more aggressive.
Since 2004, Microsoft’s Security Response Center (MSRC) has categorized all reported Microsoft security vulnerabilities and found that about 70% of its annual patches are fixes for memory safety vulnerabilities. The main reason for this result is that Windows and most other Microsoft products are primarily written in C and C++, which are both memory-unsafe languages.
If these vulnerabilities can be eliminated, it would significantly improve software security while reducing the cost of patching vulnerabilities. Thus, Microsoft began exploring the use of memory-safe languages like Rust as alternatives to C and C++ to improve the security of applications. Additionally, inspired by Rust, Microsoft is also developing its own memory-safe programming language, Project Verona.
Microsoft’s optimism about Rust is evident. In September this year, Microsoft Azure CTO Mark Russinovich’s public statement sparked much discussion.
Russinovich stated on Twitter: “It’s time to stop creating any new projects with C/C++. If you need to start a new project and require a non-GC language, I recommend using Rust instead. For safety and reliability, the industry should announce the deprecation of C/C++.” However, he emphasized that it is not about completely replacing existing C/C++ code but rather “for new tools, I would lean towards Rust.”
In response to this view, Bjarne Stroustrup’s reply was even more “spicy”: “It is not uncommon for people—especially executives—to be enamored with new things that promise to make their lives easier. Moreover, supporting new things is far more exciting than solving known issues with old and established tools. However, new languages often require years of time and significant effort to match the capabilities of mature languages across their wide application domains. Enthusiasts rarely see this, and their comments are often one-sided.”
At the same time, Stroustrup stated that he has been working to improve the safety of C++ for many years, and it is now possible to achieve guaranteed perfect type and memory safety in ISO C++. “It is important to note that every ‘safe’ language, including Rust, has vulnerabilities that allow unsafe code.”
03
Rust Joins the Linux Journey
Finally Appearing After Much Anticipation
The rapid rise of Rust is inseparable from the introduction of top-tier projects. The question of when the Linux kernel will support Rust has always attracted attention.
Since Rust emerged, many have called for the addition of Rust language support in the Linux kernel, leading to the formation of an organization called “Rust for Linux.”
As early as 2020, Linus Torvalds responded to related questions, and he did not deny this proposal. At the Linux Plumbers Conference 2020, kernel developers generally reached a consensus: there is no need to rewrite the existing kernel in Rust; focus should be on new code that can be written in Rust. Since then, Linus has maintained a watchful and open attitude towards this.
Is it possible for Rust to become the second official language in the Linux kernel besides C? The answer is affirmative.
However, it was initially thought that Rust would be merged into the kernel in version 6.0, but this did not happen. The main reasons for this are twofold: one is handling non-standard Rust extensions, and the other is the instability of the Rust compiler. Linus expressed that he is more concerned about the latter reason, as the reliability and stability of the Rust compiler are more important.
This year’s LPC conference held a small meeting focused on Rust. At the meeting, an engineer from Western Digital, Andreas Hindborg, delivered a notable presentation centered around Rust-based NVMe drivers.
Currently, the Linux kernel already has excellent NVMe drivers written in C, which do not need replacement. However, given the widespread use and importance of NVMe drivers, using Rust to write NVMe drivers is also a very interesting attempt. Benchmark results indicate that while the Rust NVMe driver is still in its early stages, it has performed well—showing that the Rust driver can achieve performance comparable to the C driver.
Just after the LPC conference, at the 2022 Linux Kernel Maintainers Summit, Linus proposed merging Rust support into Linux 6.1. He stated that one reason he hopes to see Rust in the kernel is to encourage new developers to explore the kernel. However, he also reminded that currently, “Rust is only used in core infrastructure.” Nevertheless, this will be a historic first step for both Rust and Linux.
04
The Competition Between Old and New Languages
Only Time is the Eternal Dealer
In the programming world, the competition between old and new languages has been ongoing for a long time. Many people expect Rust to rival C++, just as TypeScript does to JavaScript, and Kotlin does to Java.
However, in fact, the two are not in a “kill or be killed” relationship. Some C++ enthusiasts do not completely reject Rust, and some advocates of Rust may not fully understand Rust, just like a certain netizen’s ironic remark: “They don’t write a piece of code, but they’re trying to rust everything.”
Innovation is certainly an inevitable part of technological evolution, but the reason why established programming languages like C++, C, and Java have their current status is not a result of a day’s work. Moreover, any language that seeks to address the shortcomings of C++ must collaborate with C++ and reuse C++’s wheels.
Today, Rust is still a young language; perhaps we can argue whether Rust provides the best model for asynchronous programming and how it helps developers escape garbage collection, but to discuss whether it will ultimately replace C++, it is clearly too early.
For Rust, whether you love it or hate it, you cannot deny its rapid rise, but what the future holds still needs the test of time. As Microsoft chief engineer Nick Cameron said, Rust is currently in a good development situation: increasing popularity, more contributors, and applications in some important areas. But in this ever-changing era, transitioning from a research project to a new, rapidly evolving language, and then to a popular, mature project is a difficult evolutionary process.
For developers, Rust may or may not be suitable for you or your project; it may or may not be the optimal solution for creating related programs. But at least it provides a new choice, increasing more paths for exploration and imagination. As Peter Wayner summarized in “Seven Reasons to Love/Hate Rust”: “As a language, Rust is novel, learning it can stretch one’s brain. As programmers, it gives us reasons to rethink our challenges, redefine our goals, and start looking for the best way to write modern software. What could be better than that?”

Reference links:

https://www.theregister.com/2022/10/17/google_kata_os/?td=rt-3a

https://www.theregister.com/2022/09/28/is_it_time_to_retire_c/

https://www.sohu.com/a/589872952_121124371 https://www.infoworld.com/article/3675391/7-reasons-to-love-the-rust-language-and-7-reasons-not-to.html

<END>

¥9.9 grab 980 yuan “McDonald’s + KFC” exclusive card!

Unlimited use throughout the year!

👇👇

Is It Too Early to Replace C/C++ with Rust?

【☝🏼 Click for more details】

Is It Too Early to Replace C/C++ with Rust?

  Recommended Reading:

Exclusive customization, geek hoodies that programmers understand!

Four major languages strengthen their dominance, Rust threatens C/C++

Xiaomi engineer submits optimization patch and is criticized, Linux kernel maintainer: too crazy!

When a programmer is frantically typing, what is he actually doing?

Is there an advantage to being computer science trained?

Office 2019/2021 Professional Enhanced Edition, genuine lifetime authorization!

Is It Too Early to Replace C/C++ with Rust?

Leave a Comment