02: Why Rust?

Why Rust, dispelling common misconceptions and why not Rust.

After working with Rust for a year or so, with two production level projects completed (fluttercrashcourse.com and this website), I've gathered a lot of notes, insight, learning material but also have collected the mistakes I've made which took up some notable amount of time.

So before we start the course, I think it's best that we cover some of the basic benefits of Rust, some common misconceptions about the language and also some reasons why not to learn Rust.

Point 1 of 3: the benefits of Rust

Here are some standard benefits you should be aware of if you are considering a Rust course. Many of these are cited from Rust's website. I recommend investing a few minutes to take a look at what that site has to offer.

So here are the main benefits of Rust:

  1. Performance: Rust allows users to craft highly performant and memory efficient applications.

Side note: These applications can range from a highly reliable, system critical API, to a game, or a CLI tool down, software for embedded devices or even operating system tools. Many companies reach for Rust for system critical services and APIs for example because there's no garbage collector, which means no large dips in performance under load. There's also no runtime, which contributes to Rust's rock solid performance under load.

  1. Rust offers a rich type system, high level abstractions but provides low level control: Rust's standard types are easy to learn if you come from other strongly typed languages such as Java, C# or even Typescript but it also has many others that provide fine grained control over how resource efficient your application is. It also provides some great features out of the box, such as Macros (a zero-cost abstraction, which is huge benefit) and pattern matching which allows developers to implement powerful abstractions and write expressive code.

  2. Rust is reliable and secure: it offers strict checks to guarantee memory and thread safety. This means that many types of bugs can be exposed at compile time versus run time. More and more companies are pivoting from C++ to Rust, for example, to mitigate the risk of potentially severe security risks. Check out this article, "The ‘Viral’ Secure Programming Language That’s Taking Over Tech" which provides a good overview on this topic.

  3. Rust has Excellent tooling, community and developer experience: from Rust's excellent package manager, cargo to its documentation but most importantly, it's community and well built, comprehensive ecosystem of mature libraries, it is a great time to be a Rust developer. I've found this Reddit post to be an insightful, community driven discussion on this. In addition, compiler warning and error messages are descriptive and very well explained. Rust is also in a maturity sweet spot: new programming languages take years to mature and Rust has gotten enough adoption and libraries for it have developed enough to offer a rich developer ecosystem. Major companies are sponsoring Rust such as Microsoft, Amazon, Mozilla, Figma, Cloudflare, Facebook, Discord, to name a few. This is also an interesting list of Rust's uses at various companies.

  4. Rust saves organizations money: how do you pitch Rust to your company? Well, first off, if you're running applications in the cloud that require significantly less resources, because they are written in Rust, the pay-off is huge. Second, if you're running mission critical applications, Rust is a cost saver since it will mitigate costly security vulerabilities and production incidents due to unstable code.

You can read up more on the benefits on Rust's website.

Point 2 of 3: common misconceptions of Rust

  1. A common misconception is that 'Rust is mainly a systems programming language'. While it's trust that Rust has been widely adopted amongst systems programmers, such as it being used more and more in the Linux kernel and for major projects using WebAssembly or heck, even Deno.js, Rust is being adopted more and more for mission critical APIs such as Discord's switch from Go to Rust. In my view, Rust can easily be a great language (in some situations) for backend development and web APIs. actix_web and Rocket are some examples of popular web API libraries.

Side note: for frontend development, I still do use frontend component based Javascript libraries in conjunction with Rust. I personally like Astro for sites that benefit from pre-rendered static content mixed with SSR or Solid for a powerful but simple frontend web component library.) If you still want to explore Rust with pure HTML though, check out Askama (which has some cool features like rust-analyzer errors for dynamic HTML templates or even malformed HTML.

  1. Compiler speed hinders productivity: while Rust programs must be compiled, it is not that big of a deal as one would think. There's constant progress being made in this area (example). In my view, it is not necessary to be constantly in any case, because of the rust-analyzer built into common IDEs such as VSCode, you can tackle potential errors as you write code in real time.

  2. Learning curve: many people complain that Rust is difficult to learn. In my view, learning Rust helped me become a better engineer. Difficult concepts such as ownership and borrowing indeed have a learning curve but for basic applications or API development, once you get a handle on it, fighting Rust's borrow checker is not common, in my personal experience.

At the end of the day, the learning curve isn't so bad if you already have some experience with strongly typed languages or even TypeScript. Features like Macros, option, result can take awhile to learn but for folks coming from the Java world, it is not so difficult. These are super powerful features, actually and once you get the hang of them, they are commonly used and make code concise.

Point 3 of 3: when not to use Rust

I'll keep this section simple.

  1. If you're new to programming: it's best to get started with a simple course on JavaScript or Python to understand the basics of say, web-application development. And if you're completely new to programming, check out my course on HTML.

  2. If you're mainly developing simple web-applications for the foreseeable future: if this is the case, just focus on getting good at web design, HTML, CSS and JavaScript. I personally use Astro for personal sites as it supports many features, is on the up and up and is not over bloated with features. Heck, maybe I'll create a course on this in the future.

  3. If you're doing mostly mobile development: this is a case where, if you're investing in this space for the foreseeable future and/or need to implement only a very simple backend API for your mobile app, just use something simple like Supabase. My Advanced Flutter course covers Supabase (which is a powerful, Firebase-like "platform as a service" with a free tier and offers many mobile and web libraries).

Summary

At the end of the day, if you just "feel" like you want to dive into Rust, just go for it! Even if you learn some basics, Rust will make you a better programmer in my opinion. I've used Rust on and off for a few years now and I still love it. It's just most likely overkill for super simple projects.

Did you know? seenickcode.com's backend is written in Rust! 😉