skip to Main Content

Programming with Rust

Rust is a young programming language; not brand-new, but not old or rusty by any means.

Rust was first introduced at Mozilla in the 2010s, and it proved its worth at the core of Firefox. The parts written in Rust made the browser fast. The programming language was useful in implementing parallel layout algorithms and utilizing graphics cards.

Using Rust also made the browser more stable and secure. In one of the Mozilla Hacks articles, Diane Hosfelt says that she went through all of the security bugs in Firefox’s style component since its publication in 2002 — and found a total of 69 of them. She writes that 51 of these bugs would not have been possible if the component had been written in Rust from the start.

Rust makes programmers feel confident that it is difficult, almost impossible, to make the errors typical of other languages. It is usually difficult to avoid memory management errors in programming, and C++, for example, gives far too many chances for you to make mistakes.

What does Rust offer?

Every year since 2016, Rust has been voted the most beloved programming language in the Stack Overflow Developer Survey.

Rust appeals to developers by offering something familiar. The familiar rhythm of parentheses and braces make many C and C++ users feel safe.

For me, the most unpleasant thing about Rust is particularly the flood of parentheses and braces and the unnecessarily long format. Since there was a chance to create a programming language from scratch, they could have copied the minimal syntax along with the other good features they got from Haskell. After all, Haskell successfully makes room for the relevant things while leaving out the superfluous “noise”.

Once I manage to get over the external issues, I admire the better aspects of the language. The best thing about Rust is that it focuses on speed, safety, and parallelism. Just the kind of things that matter when I want to build mobile robots.

Rust offers sturdy static typing and clear semantics. Rust takes a strong stance against undefined behavior: it is not allowed. In C++, undefined behavior is always lurking in the shadows, from where it may emerge at a bad moment. This makes programmers live in a state of constant low-level anxiety.

Regarding parallelism, Rust is precise yet careful. The compiler checks that the code is not accidentally interfering with a memory that belongs to a different thread and that no other similar, minor mistakes are made. This automatically reduces the possibility of parallelism errors that are difficult to discover.

Speed was not compromised when developing Rust’s admirable features. Instead, coders sometimes have to wrestle with the compiler to get their way, and, in the end, one of them always gives up. It is worth remembering that the compiler is a strictler for a reason. It wants to make sure that the product does not contain errors that even a machine could have avoided.

Rust is becoming more and more popular. It is equally liked by enthusiasts, scientists, system developers and game coders. Some have already declared that they will no longer be coding in C++.

In November, as Mozilla Foundation reallocated its resources, Rust’s maintenance was transferred to Linux Foundation. I believe that Rust will find a good home there, and I’ll continue following the development of the language with interest.

Read more:
» RustDDS – Data Distribution Service implemented in Rust

Harri Järvi
Software architect