Why Windows Chooses Rust Programming Language Over C++

Why Windows Chooses Rust Programming Language Over C++
Click the above “Programmer Software Library” and select “Star
Stay updated with the latest software news and insights!
The optician store of the Programmer Software Library!
Mingmin Hengyu from Qubit AI | WeChat Official Account QbitAI
Replacing C++, Rust is truly set to rewrite everything!
After gaining favor from major companies like Linux, Google, and Alibaba, the latest explosive news—
Microsoft has rewritten the Windows kernel with 36,000 lines of Rust code.
Moreover, the pace of progress is quite fast; a teaser in April indicated that within two weeks, the internal preview of Windows 11 had already adopted it.
The CTO of Microsoft Azure excitedly tweeted:
If you joined the Windows 11 Insider Preview, you will be the first to experience the Rust-supported Windows kernel!
Why Windows Chooses Rust Programming Language Over C++
The rewritten kernel primarily includes DWriteCore and Win32 GDI projects, and has passed all Windows boot tests.
Among them, Win32 GDI was written in the late 80s and early 90s, and is over 30 years old code.
The reason for its replacement by Rust is straightforward from Microsoft:
Rust offers extremely high memory safety, and many unsafe subroutines in the original kernel have disappeared after the rewrite. Additionally, Rust is more concise and efficient.
Public information also indicates that over time, the adoption of Rust in the Windows kernel will be significantly expanded.
Not only favored by large companies, Rust has also been rated the “most loved programming language” for several consecutive years in the Stack Overflow Developer Survey. Recently, foundational Unix tools like sudo and su are also being rewritten in Rust.
However, it is a bit surprising that Rust was originally invented to fix elevators???

Deciding to Develop a New Language After Climbing 21 Floors

Everything began on a day in 2006 when a guy named Graydon Hoare living in an apartment found the elevator broken again.
For the nth time, he cursed while struggling to climb to his home on the 21st floor. He couldn’t understand why the elevator system was so prone to failure. It shouldn’t be that way!
Why Windows Chooses Rust Programming Language Over C++
As a programmer at a major company, Graydon felt that this issue could be resolved.
At that time, he was 29 years old and working at Mozilla, the company behind the open-source web browser Firefox. As an industry insider, he knew that most elevator failures were due to programming languages that easily introduced memory errors, leading to software crashes.
At that time, elevator software was often written in C or C++.
While these languages are compact and fast, they are also prone to memory errors that can cause system crashes and even security issues.
So, not wanting to climb stairs anymore, Graydon decided to create a new programming language.
The goal was to develop a language that minimizes memory errors, ideally shorter and faster.
Thus, the Rust language was born.
Why Windows Chooses Rust Programming Language Over C++
The naming of Rust is also quite interesting.
Rust shares its name with a type of fungus, scientifically known as plant rust, which Graydon described as “over-designed for survival.”
This fungal organism has a completely distributed biological structure, meaning that removing any part does not affect its survival, showcasing its robustness.
Throughout its lifecycle, the Rust fungus has five life stages, three of which can revert to a previous stage, almost like a butterfly turning back into a caterpillar to regrow.
Additionally, Rust fungi can parasitize multiple hosts, which reflects Rust language’s emphasis on interoperability.
Why Windows Chooses Rust Programming Language Over C++
Plants infected with Rust (Apologies to those with mycophobia!)
After years of solo development, in 2009, Rust received support from Mozilla’s research institute; the project was announced to the public in 2010.
During its development, Rust established a highly active community where any developer could directly report bugs or contribute source code.
In May 2015, Rust 1.0 was officially released.
In just a year, Rust garnered countless enthusiasts. Since 2016, it has been rated as the “most loved programming language” in the Stack Overflow Developer Survey for seven consecutive years.
The reasons for its continued top ranking include its speed, high memory utilization, and prevention of segmentation faults.
In short, it is a powerful tool that can replace C/C++ in certain areas.
Thus, there is a saying in the coding community that compares Rust to parkour: it can perform high-risk maneuvers but is less likely to injure itself.
In contrast, C++ can be likened to playing with a chainsaw on fire.
Why Windows Chooses Rust Programming Language Over C++
With the development of Rust, Graydon became well-known.
In the following years, he also participated in the development of Swift.
This is an interesting story. Compared to being a team leader, Graydon seems to prefer frontline development.
Why Windows Chooses Rust Programming Language Over C++
He once responded to why he left the Rust team, stating that around 2013, his personal life was severely impacted (due to divorce), which left him with little energy to lead the Rust team. Later, he worked on some low-key, non-urgent projects at Mozilla before leaving the company.
In early 2016, he received a call from the Apple team, indicating they were looking for programmers to help develop Swift, “it was a non-leadership position, which I preferred.”

Becoming the Darling of Major Companies Due to Safety

However, at this point, the legendary story of Rust is only halfway told.
With its high safety focus, its popularity among major companies has been increasing in recent years.
Not just Windows, mainstream systems like Linux and Android have also embraced Rust one after another. Amazon Web Services, Microsoft, and Google have maintained good relationships with Rust.
The main reason for this might be that C/C++ really struggles with memory safety.
Why Windows Chooses Rust Programming Language Over C++
For instance, Microsoft has been interested in Rust for several years, considering it a good way to eliminate memory safety vulnerabilities before product delivery.
In 2019, Microsoft acknowledged that 70% of the vulnerabilities disclosed by CVE in their products were due to memory safety issues caused by using C/C++.
Rust’s toolchain focuses on identifying potential vulnerabilities in code, which ideally reduces the likelihood of code being attacked by hackers.
On the other hand, the Linux kernel has also introduced Rust.
Last year, at the 2022 Open Source Summit hosted by the Linux Foundation, Linus Torvalds suddenly announced that Rust might be included in the next version!
This means that the official will merge Rust for Linux PR into the mainline of the Linux kernel.
(Rust for Linux is an organization advocating for the integration of Linux and Rust.)
Why Windows Chooses Rust Programming Language Over C++
It is worth noting that prior to this, Rust’s support patches had already been released up to the seventh version.
When this news was heard on-site, applause erupted, and Linus took a while to calm everyone down.
Months later, Linux version 6.1 was released, adding support for Rust, making it the second official language after C.
Google’s actions were actually earlier.
With the release of Android 12 in 2021, they announced support for Rust. Since then, they have been expanding the use of Rust in Android open-source projects.
However, Google’s approach is not to immediately replace C/C++ with Rust, but to write new code in Rust.
According to official data, C and C++ still dominate, while Rust’s proportion is gradually increasing.
Why Windows Chooses Rust Programming Language Over C++
By the end of last year, Google stated that no security vulnerabilities had been found in the parts of Android written in Rust.
This result is significant because it indicates that Rust can effectively prevent the most common vulnerabilities in Android—namely, memory safety vulnerabilities. Google’s 2022 data shows that memory safety vulnerabilities account for a very high proportion of various vulnerabilities.
Why Windows Chooses Rust Programming Language Over C++
In many components written in C/C++ (such as Bluetooth, NFC, etc.), there is one vulnerability for every thousand lines of code. Based on this ratio, Rust has likely prevented hundreds of vulnerabilities.
Furthermore, based on its high concurrency advantages, using Rust in Android can further balance system security and latency; generally, some security measures can slow down programming languages.
For example, using the new UWB stack can save several megabytes of memory and avoid some IPC delays by running through existing processes.
Amazon Web Services also has a particular fondness for Rust, due to its excellent performance in energy savings.
A study tested 27 programming languages and found that C and Rust are 50% more efficient than Java and 98% more efficient than Python in energy utilization.
However, the issues with C have been discussed many times, with many memory safety vulnerabilities, so overall, Rust wins again.
Why Windows Chooses Rust Programming Language Over C++
In fact, major companies are not just fond of Rust; they are even doting on it.
In 2020, Mozilla, the company behind Rust, announced large-scale layoffs, and the Rust team was cut, leaving Rust’s future in great uncertainty.
To mitigate this concern, companies like Amazon, Microsoft, Google, and Huawei jointly initiated a non-profit foundation for Rust, promising to invest about $1 million over two years to support Rust project maintenance.
In the industry, there are countless stories about Rust.
Recently, two core Unix utilities, sudo and su, are being rewritten in Rust; previously, GitHub revamped its search engine based on Rust; and a Go service from Discord has also been rewritten in Rust…
(On a side note, Rust is also popular in the cryptocurrency field.)
However, Rust does have drawbacks, such as becoming more challenging to learn later on, and the initial development speed is much slower than that of Go or Java.
Thus, while Rust has a high approval rating, its “box office” performance is still quite average, and it may even be labeled as a “niche language.”
Especially in China, the job market for Rust can be described as “scarce.”
Some netizens hold a pessimistic view:
Why Windows Chooses Rust Programming Language Over C++
For this reason, Rust is also further optimizing itself.
According to its released Rust 2024 roadmap, the official team will intensify efforts to reduce the learning curve and strengthen ecosystem connectivity.
Therefore, how Rust will proceed in the future is also worth looking forward to~
Reference Links:[1]https://www.thurrott.com/windows/windows-11/282995/first-rust-code-shows-up-in-the-windows-11-kernel[2]https://www.technologyreview.com/2023/02/14/1067869/rust-worlds-fastest-growing-programming-language[3]https://www.reddit.com/r/rust/comments/7qels2/i_wonder_why_graydon_hoare_the_author_of_rust/[4]https://arstechnica.com/information-technology/2023/05/two-core-unix-like-utilities-sudo-and-su-are-getting-rewrites-in-rust/[5]https://security.googleblog.com/2022/12/memory-safe-languages-in-android-13.html?m=1[6]https://aws.amazon.com/cn/blogs/opensource/sustainability-with-rust/
Why Windows Chooses Rust Programming Language Over C++

Previous Articles

01. Recommend another essential tool for Windows
02. Remove download restrictions from cloud storage, no need to start the client for large files
03. Give wings to Windows, a magical tool that can instantly accelerate your PC
04. Is the webpage you want to see 404? We suggest you use this to solve it
05. This time, the C drive is really saved!

Leave a Comment