How Rust Coding Language Captured the Hearts of Developers Who Use It
For five years in a row, Rust has been at the top of Stack Overflow’s list of “Most Loved” programming languages among developers. Eighty-six percent of developers surveyed who use Rust expressed interest in continuing to use it, leaving the second best-loved language — TypeScript — trailing by almost 20 percent.
But Rust isn’t anywhere close to the most commonly used language. The same survey found that only 5 percent of developers have used Rust. That puts the language way below Rust’s closest cousin, C — both languages are considered “systems” languages, suitable for writing operating systems and low-level platforms that run other software.
But it’s not really fair to compare Rust with C, said Esteban Küber, who contributes to the open-source Rust compiler, works at healthtech startup Commure and mostly programs in Rust. C has been around since the early 1970s, while Rust first appeared in 2010.
“It is a very young language — [Rust] 1.0 was 2015,” Küber said. “And we’re talking about industries where the turnaround is very slow, and the lead times are very high.”
He said that, for systems languages in particular, adoption rates tend to be slower due to the nature of the businesses that use them, which often have hardware components and large codebases that make change expensive.
“Your TV at home has a computer, and that is going to be running C,” Küber said. “Even if you were to start a greenfield project today — to have TVs that are running Rust — it’s going to need to interact with C, and it’s going to be a few years before that will hit the market.”
A High-Level Language for Low-Level Software
For Rust’s community of devoted users, the language’s good reputation is deserved. It blends useful features taken from other languages with new ideas.
Küber said Rust’s creators drew inspiration from functional programming languages — another category of languages with a small but enthusiastic base of users. Functional programming was built for readability and maintainability, which gives these languages, and Rust, an easy-to-read feel.
“It’s very common to write very high-level code that looks like you are performing mappings and fold operations, and all of those compose really well,” Küber said. “But, because of the way the optimizing compiler works, by the time it gets compiled to the final binary, the final assembly code looks exactly the same as if you had written for loops.”
Küber said he enjoys writing Rust code because it looks clean and easy to follow, but is also capable of low-level, close-to-the-hardware hijinks.
“You can write very high-level code and, at the same time, have a function that operates directly with bits that are flowing in the computer.”
“There is a huge amount of flexibility,” he said. “I’ve seen some Python modules that have been translated verbatim into Rust — and, other than some syntax changes, it works. So you can write very high-level code and, at the same time, have a function that operates directly with bits that are flowing in the computer ... that is something I have rarely seen in the industry.”
Part of Rust’s flexibility comes from its unsafe code block feature. The C language’s ability to manipulate memory directly and work close to the hardware makes it great for programming systems software, but those qualities also make for code that’s prone to memory errors. Developers who don’t need to program using C often avoid it for that reason, preferring languages that take care of memory allocation automatically.
Rust’s unsafe feature allows developers to have the best of both worlds. Most Rust code is written in the default safe mode, with the compiler taking a conservative approach to memory allocation, but developers also have the option of declaring blocks of code unsafe — granting them the ability to write high-performing code.
“That is what Rust does, it segregates the things that can be done safely [from] parts where the programmer takes responsibility,” Küber said. “You can restrict where you have full access to memory to a very small portion of code and provide some assurances that you are writing a safe abstraction of that memory interaction.”
Unsafe blocks also help speed up code reviews, because reviewers know to pay special attention to potential memory-management errors within the blocks, while being confident those errors won’t appear in the rest of the code.
Meet Your New Coding Buddy, the Compiler
Küber said Rust is also redefining the role of a compiler. In addition to the usual jobs of turning developer code into machine code and catching errors, the Rust compiler also helps developers learn how to code in Rust more effectively by being “actively helpful.”
People learn to code by reading documentation, trial and error, and asking others for help, Küber said.
“The idea is, we can actually use the compiler itself as a way of removing the need to go to a forum,” he said. “We can change the compiler to make it easier for people — just outright tell them, ‘Hey, you should have done this instead of what you’re doing.’ And give them a link for the documentation if they care to learn about the details.”
According to Küber, having the compiler help teach the language is useful for growing the Rust developer community, especially for such a young language. He said experienced Rust developers find it helpful as well, which may explain Rust’s five-year streak on the “Most Loved” list.
“I can just focus on the problem at hand, and I can become a bit more adventurous in how I write my code.”
He likened the experience of interacting with the Rust compiler to having a personal tutor or pair programming. While programming, he feels the compiler has “got his back.”
“Usually, early in the morning, I’m writing some code and I hit compile, and the compiler gives me an error,” Küber said. “I look at the error and I know how to fix it. It’s a two-line change, but the error that the compiler gave me is something that would have gone by in another language. ... If I were to run that same algorithm in another language, it very likely would have bugs.”
Rust’s robust safety-checking mechanisms allow developers to be more comfortable thinking creatively.
“With Rust, I can just focus on the problem at hand, and I can become a bit more adventurous in how I write my code,” Küber said. “I write code that I would not think about writing in other languages, simply because I won’t feel confident enough that they will be able to pull it off with the same performance characteristics and the same efficiency.”
Rust’s Future Is Being Built Today
Aside from its technical advantages, Rust also has a supportive developer community, Küber said.
“It’s an extremely welcoming community,” he said. “People try to be available for questions — it’s not uncommon for somebody to ask a question on Twitter and suddenly have three or four different prominent engineers in the community find a solution to the problem.”
Rust still has a long way to go to achieve the kind of popularity established programming languages enjoy, but Küber is hopeful.
“We haven’t reached the critical inflection point where using Rust is a natural decision in all spaces, but I think we are already there for specific issues,” he said.
“We haven’t reached the critical inflection point where using Rust is a natural decision in all spaces, but I think we are already there for specific issues.”
As more developers try the language and develop libraries to support different use cases, companies may become comfortable testing out the relatively young language.
“If you are writing something in a new niche that nobody else is using, it means that you’re taking on the responsibility of writing a lot of code from scratch, and that is not something that a lot of companies will want to do,” Küber said, explaining companies’ slow adoption rate.
But he said there were already good foundational blocks in place for Rust, and volunteers are doing the work necessary to create the type of battle-tested libraries used by languages like Python and Java.
“Ecosystems take time to develop,” Küber said.