What is Rust programming?
Rust programming language is open source and has been the "most loved language" on developer community Stack Overflow's annual survey for the last four years. At the same time only a very, very small number of developers actually use Rust today – a July 2020 look at the PYPL PopularitY of Programming Languages Index ranks it at number 18 with just .81% interest. (For comparison Python is at nearly 32% and Java is over 17%.)
So why the intense love of Rust? To put it simply, it was created to solve problems present in other languages and if you can take the time to unlock its (admittedly difficult) secrets, you're rewarded with cleaner, faster, and most importantly, safer code.
Antony Saba, a senior security engineer with Strategic Security at GitLab, recently talked about Rust during a company-wide series of meetings (Contribute 2020). He speaks from experience as his last employer was a Rust-based company. "Okay, so what's Rust's promise?" Saba asked. "Rust's promise is that it should be easier, and everybody should be able to fearlessly write at a systems level and not have to worry about memory safety or thread safety, or at least worry about it in the way that is supported by the language and the tools."
Let's unpack what that means.
Where the Rust programming language started
The open source Rust community describes the language as fast, reliable and productive. "Hundreds of companies around the world are using Rust in production for fast, low-resource cross-platform solutions," the organization says. Firefox and DropBox are two well-known users of Rust today, and Mozilla (creator of Firefox) was the first original supporter of Rust.
Think of Rust as the answer to a data-rich problem that will likely need lots of computational cycles. Mozilla's Rust documentation specifically calls out the language as ideal for "game engines, operating systems, file systems, browser components and simulation engines for virtual reality."
Under the hood of the Rust programming language
Rust is a bit of a hybrid, according to Mozilla's Rust documentation. Rust offers developers the syntax advantages of high-level languages with the "control and performance of a low-level language," the documentation explains.
Rust is a statically typed language rather than a dynamic one. Though developers like to argue the merits of both, Rust, like popular TypeScript, eliminates the frustration of "dynamic typing." Data is constrained and checked by a compiler so confusion is minimized. Rust also makes it very hard to ignore errors – Steve Donovan, author of "A Gentle Guide to Rust," jokes it can be hard not to think the compiler is shouting at you when you make a mistake.
Donovan identifies Rust's key principles as:
- Strictly enforcing safe borrowing of data
- Functions, methods, and closures to operate on data
- Tuples, structs, and enums to aggregate data
- Pattern matching to select and destructure data
- Traits to define behaviour on data
All of those guardrails lead to a language that can create fast-moving code with few things that slow it down. There's no runtime or garbage collector making Rust ideal for applications where memory usage is at a premium (like embedded devices). But if there is a place where Rust really stands out, it's security. Donovant points out that Rust is "safe by default," unlike C or C++. No one can corrupt memory by default, he writes.
The Rust programming language and productive coding
After three years of working in Rust, Antony was quick to say he's probably more productive with the language than any other.
"I really do feel like Rust was the most productive language I've ever used," he says. "Once you are doing everything in that functional style, you're writing less code, but it's still clearer, because you don't have temporary variables. They're a thing that you don't really end up using when you're writing code that way. So, to me, it's those little things that I get the productivity out of."
Rust can be touchy, but rewarding
Productive, sure, but there's a learning curve with Rust.
"It's true the borrow checker is the hardest part," Antony says. "But the thing is, once you get past that, there is a serious dopamine hit when that program compiles, because it means now you only have your own logic errors to deal with. Part of that pain is explicitly some of the things that you assume, and some of the little white lies that you tell yourself when you're starting, especially with a C program. Because when you start your C program, it's like, 'all right, I have a couple command line parameters, I don't really want to write all my functions just to pass them, so I'm just going to declare a couple global variables and shove them in there, and I'll clean it up later.' Right? It's one of those little lies we tell ourselves. But you can't have immutable global variables in Rust. It just won't let you. You have to wrap it – you may as well just do the functions right. They're going to use your command-line arguments. It's the same with thread safety. You kind of have to do that upfront, and you don't get to make that assumption."
Looking to the future of the Rust programming
Rust has a bright future, even if it might not be as widespread as other languages, Antony explains. "I don't think it's ever going to be as popular as Go, just because Google is Google, and there's a lot of places that Go is really good for," he says. "But for those places where you really want that fearless development, I think it'll continue to have a strong hold there."
Watch Antony's Rust demo in full here:
Read more about programming languages:
Can we solve the COBOL programmer shortage?
Why we use Ruby on Rails to build GitLab
How Modern C and C ++ work
Cover image by Zsolt Palatinus on Unsplash