Rust: A Systems Language for Coffee Break Coders

As self-taught programmers - and maybe even as traditionally educated programmers, I'm not sure - we generally get pushed towards learning one of maybe three or four languages: JavaScript, Python, Java, or C# (I imagine Swift will get added to this list once it's been around a little longer). It's for good reason that we get pushed towards these languages. Each one has the majority of the following characteristics: simple, low barrier to entry, established/heavily used in the market, have great IDE support, etc. (if you've never seen it, check out theStack Overflow Developer Survey for insight on the language landscape).

One thing all of these languages have in common is automatic memory management. Each of these languages has some type of garbage collection that can handle memory management for us. Everything "just works", and it's one less thing we have to worry about. But what if we're interested in some of the lower level "stuff" like high-performance video games, browser engines, or operating systems. Most of these programs are written in languages that don't have garbage collection, like C and C++. So what do we do? Bite the bullet and learn C and C++? I certainly wouldn't stop you. I believe that if a person is passionate enough, they'll find a way to overcome any obstacle. But if you're like me and are intimidated by C and C++, but still desperately want to get into the game, Rust might be you're best friend.

So why Rust?

Hack without Fear

Systems programming is scary. You can really mess some stuff up if you aren't careful, and the bugs you can produce are in a different league. Thankfully, one of Rust's main goals is memory safety. To put it simply, if you can get your code to compile, chances are it will be safe and reliable. The trade-off is that the learning curve is steep, and you're going to get a lot of error messages from your compiler.

Personally, I'll take it. At least I'm learning how to write better code instead of developing bad habits that I might not ever discover. There is a fantastic article about Rust called fire flowers that will do a better job than I ever will of explaining why Rust is fantastic for newcomers to systems programming, but the gist is that Rust is like the fire-flower from Super Mario. It is the tool that allows us to become a fearless fireball slinging code-wizard. A dream come true.

rust-fire-mario-equation

Useful Error Messages

I've already kind of touched on this, but Rust's beginner friendly error messages are a breath of fresh air. This might sound ridiculous, but I honestly feel like the Rust compiler has been a mentor to me. Every time I get a compiler error I feel like I'm learning how to write better code and how to be a better programmer. Here is a simple example of what these error messages look like:

Cargo

Cargo is Rust's package manager and build tool. I haven't done anything robust enough in Rust to make use of crates (Rust packages) or need a build tool, but it's nice to know it will be there when I'm ready to use it. I'm sure there are tools for C and C++ that do something similar, but its nice when it all works together like it does in Rust.

Built in Testing

I never realized this until recently, but there are not many resources out there that teach you how to write tests for your code. More on this in a later post, but being able to write tests without having to download and configure an external tool is a breath of fresh air. Again, this "batteries included" approach to a programming language makes getting started that much easier. The less you have to worry about things other than code, the better.

Community

Unlike some other communities, Rustaceans seem unusually and refreshingly respectful and willing to help. This may be because Rust is relatively new, and most Rustaceans are just happy to see people adopting the language, but that shouldn't detract from the fact that it is a very accepting community. Try out the New Rustacean or Rusty Spike Podcasts to get a taste.

Rust Language Server

When you're learning a new language, the faster you can get feedback on your code the better. Just a year ago, there wasn't a way to get feedback on our Rust code until we attempted to compile. Those days are over. With the new Rust Language Server support, we can get immediate feedback on our code in the same way we can for C# in Visual Studio, Java in Intellij/Eclipse, and Python in PyCharm. Type information, potential errors, code completion, etc. It's not quite as advanced as the tools I listed for other languages, but it's getting there, and chances are there is a plugin for your platform of choice: Visual Studio Rust, VS Code Rust, Intellij Rust.

Reference: The Rust Programming Language - 2nd Edition, Fire Flowers, New Rustacean Podcast, Rusty Spike Podcast, Visual Studio Rust, VS Code Rust, Intellij Rust.