Rust made me nervous as a C++ programmer. Here's what changed.
Let's talk about what you need to know about Rust today (and why it’s here to stay)
Mark Russinovich, the CTO of Azure, recently sparked a conversation about a topic that has been on my mind lately.
It's an eye-catching statement that has ruffled a lot of feathers across the industry. But he has a point. What I consider to be Rust's strongest selling point is its focus on security. Rust makes programming safer and more efficient to an exacting standard — and I say this as a lifelong C++ programmer.
These high safety standards also contribute to its high performance because it's much harder to make mistakes.
It's worth mentioning that these same standards convinced Linus Torvalds to learn and use Rust in Linux 6.1 after rejecting C++ for almost three decades. For context, Linus has always been very vocal about his disdain for the C++ programming language — making his adoption of Rust all the more significant.
C++ doesn't meet Linus' standards, but Rust does. I consider that to be one stellar vote of confidence for the language.
I can't say I'm surprised by the enthusiastic reception that Rust is receiving from the developer community.
We've seen the popularity of our Rust courses skyrocket on Educative. (If you are new to Rust, I highly recommend checking out our course: The Ultimate Guide to Rust Programming. It's the perfect introduction for anyone eager to dip their toes into Rust).
And it's not just us — this marks the seventh year Rust was voted the most loved programming language in the Stack Overflow Developer Survey. Rust has captured the attention of developers looking for a safer alternative to the well-established C++ language.
But what does this mean for developers and engineering managers?
As more businesses adopt Rust for production use, it's becoming increasingly important to stay updated on the latest developments. Companies like Figma, Cloudflare, and Microsoft are already using Rust in production, so if you want to stay ahead of the competition, learning Rust is a great way to gain a serious edge. There aren't many Rust developers currently, but as more businesses adopt Rust, demand will only increase.
That said, Rust isn't going to replace C++ overnight. C++ remains one of the most widely-used languages. It has a long history of being the preferred language for systems programming, and C++ codebases are still fairly ubiquitous. Some industries (like gaming) prefer using C++ almost exclusively.
If you're a new programmer looking for your first language, then Rust is a strong contender worthy of some serious thought. However, learning C++ may benefit you more now because of its prevalence. (Knowing C++ will also make learning Rust much easier because they share similar syntax).
If you're a seasoned C++ developer, learning Rust is still worth your time. With numerous outstanding features, Rust has the potential to save time and energy across multiple scenarios. I remember one incident in particular from my days as a systems engineer where this was evident (I'll share that story with you in a moment).
In this newsletter, I'll offer some perspective on why Rust is so beloved by developers, and how it improves on languages like C++. Finally, I'll highlight some of my favorite Rust resources we have on Educative to help you get started.
Quick Facts About Rust
Rust is an open-source, cross-platform language developed by Mozilla, with its first stable release in January 2014.
Rust is strongly and statically typed, meaning you can catch errors during compilation rather than runtime.
Rust has a great package management system called Cargo, which makes it easy to install and manage libraries.
Rust eliminates many common sources of bugs and security vulnerabilities found in traditional compiled languages.
The Rust community is large and welcoming, so if you're struggling with something or have a question, chances are good that you'll be able to find an answer quickly.
Rust Features: Enhanced Security, High Performance, and Fearless Concurrency
C++ has always been susceptible to memory corruption attacks, which often result in difficult-to-solve errors that can take weeks or even months to debug. This is because C++ has free access to memory, leading to buffer overruns and stack overflow vulnerabilities.
By contrast, Rust has strong memory safety features preventing these types of mistakes from happening in the first place.
To put the scale of this issue into perspective, I once spent an entire year in one of my systems engineer roles focusing solely on C++ bugs with memory-corrupting processes. In order to avoid storing garbage data, I needed to build many checksums for saving memory onto disk.
One day, I woke up to several thousand crashes.
To fix the issue, I built an automatic dump analysis tool that grouped dumps into unique stacks. Out of thousands of crashes, only four were unique. In almost all cases, it was a memory leak or some corrupted data the process wrote that caused the crash.
Memory safety vulnerabilities can result in serious security issues and wasted time spent on debugging. Rust's focus on safety makes it a much more attractive option for developers who want to avoid these problems.
Rust makes it easy to write programs correctly because of the guardrails it provides. In most cases, you won't have nearly as many problems with memory safety as you would with C or C++.
Yes, it's still possible to shoot yourself in the foot with Rust. It's just significantly more difficult.
The features that make Rust so secure also give programs written in Rust a performance edge over other languages. In fact, Rust has repeatedly outperformed C and C++ across multiple benchmarks.
That's right. Rust can be just as fast, if not faster, than C or C++. Naturally, Rust also beats out languages like Go, Java, and Python.
Rust performs well because like C and C++, Rust is a low-level programming language. Usually, this would mean that although your code is more efficient, it is more challenging to read and write since the syntax does not abstract away low-level details. However, reading and writing Rust is surprisingly intuitive.
Furthermore, Rust is similar enough to C++ that many existing C++ codebases can be easily ported over to Rust. In other words, developers don't have to make sacrifices in the areas of performance and safety when they're striving for readability and usability. Consequently, this results in lowered development costs all around.
Rust manages concurrency problems and memory safety issues through two systems, ownership and type checking, that work in tandem to create safe and efficient concurrent programming. Ownership ensures that every piece of data only has one owner at a time, while type checking ensures that every value has a correct and consistent type.
The combination of these two systems is referred to as fearless concurrency.
In Rust, most concurrency errors can be caught at compile time rather than runtime. This is much more efficient than trying to reproduce runtime bugs, which can be time-consuming and frustrating. In addition, incorrect code will not compile. Instead, you get a brief error message with the details needed to quickly identify and fix the issue.
You can probably tell that this would have saved me quite a lot of time.
The Industry Outlook for Rust
It's clear that Rust has advantages that are impossible to ignore. I can see why Linus chose Rust over C++, and why Mark Russinovich is publicly endorsing Rust. There is an undeniable shift in the tech industry towards adopting Rust for mainstream use as a replacement for C and C++ because of its safety and security features.
Just last year, Google announced that they were joining the Rust Foundation to support its development. Rust is getting the institutional support it needs to reach its full potential, and I fully expect Rust to become the language of choice for high-performance software development as it continues to mature.
Ready to Learn Rust?
At Educative, we love bringing in industry experts to design courses that developers of all experience levels will enjoy and find useful. That's why I'm excited to share our new skill path Become a Rust Web Developer. This resource teaches the fundamentals of Rust over the course of 193 interactive lessons. By the end, you will have built your very own full-stack web application in Rust.
We also want to help people break into the tech industry. The simple truth is that there just aren't enough software engineers to meet the current needs of businesses, and there's an even shorter supply of Rust developers.
Despite recent high-profile layoffs in the news, software development remains a solid career path that isn't going away anytime soon. As the Rust language becomes more sophisticated, even more opportunities to build in Rust are sure to spring up.
Here are some more of my favorite Rust resources on Educative to get you started:
Happy learning!