Rust, an open source programming language, 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 it 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

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.

#rust #language

An inside look at the Rust programming language
6.50 GEEK