4 Comments

Rust Gets a Lot of Things Right

So some coworkers and I have been recently checking out the relatively new language Rust, and so far we’ve been very impressed.

Rust gets a lot of things right. You should check it out. If you use C or C++ on a regular basis, you really should check it out.

A Systems Language with Better Features

Rust is a systems language, but it has a lot of awesome features you don’t normally see in system languages, such as:

A Good Memory Model

It’s pretty obvious that the developers of Rust paid a lot of attention and care to Rust’s memory model. It shows. The result is a lot of very nice safety features statically guaranteed by the compiler:

  • You can’t cause segfault in Rust**.
  • You can’t leak memory.
  • You can’t dereference a null pointer. (null isn’t even a thing in Rust!)
  • Even though it’s easy to share mutable data between Tasks in Rust, the compiler only allows one task to mutate the data at any given time. And this is enforced at compile time!

The cool thing about Rust is that it provides all these cool features without sacrifices to speed or safety. Rust is still very young, and it’s already nearly as a fast as C!

Potential Usability for Embedded Systems!

This is one of the things I’m most excited about. My language of choice is Haskell, but for a variety of reasons C is still the defacto choice for embedded development.

However, fewer of those reasons apply to Rust. It’s currently possible to run Rust without an OS! It’s also possible to avoid the garbage collector in Rust, which is a big deal for embedded systems. And it’s possible that future versions of Rust will have the garbage collector as a library, which would be even better!

There are still some other catches (mostly due to LLVM) but Rust is definitely the most powerful language that I might actually be able to use on an embedded project.

A Potential Gateway Drug?

I’ve explained Algebraic Data Types to people before, and even compared them to enumerations, but probably half the time the response I get is: “Well that’s kinda cool, but I’m not sure what I’d use them for.” But when I show people the Rust enum, the response I get is: “woah, that looks ridiculously useful.”

I think Rust calling Algebraic Data Types ‘enum’ was a really really good idea.

The more people I can get to use Rust and get addicted to a world without null’s and awesome features like pattern matching and algebraic data types, the better.

** Well, actually it does let you do all of these things. It’d hardly be a systems language if it didn’t. But it forces you to put any potentially dangerous code in an unsafe block.