Recently I took a serious amount of time to work on some Rust projects. I also shared a lot of Rust related articles on my social media. Few people come to ask me about Rust and why am I using it. I think this is a good chance to write down my opinions about Rust.
So here you go.
Rust is an open-source systems programming language developed by Mozilla that focuses on speed, memory safety and parallelism. It offers the performance of C and C++ but with safeguards to stop developers shooting themselves in the foot.
Developers are using Rust to create a wide range of new software applications, such as game engines, operating systems, file systems, browser components and simulation engines for virtual reality.
“Rust changes the game when it comes to writing safe systems software. Rust provides the performance and control needed to write low-level systems, while empowering software developers to write robust, secure programs.” — Microsoft
“As a project where security is a primary focus, the type-safety and memory-safety of Rust were extremely appealing. Over the past year, we’ve found that even though Rust has a high learning curve, it’s an investment that has paid off.” — Facebook (Libra)
Rust is the most loved language four years in a row in Stack Overflow Developer Survey
Guaranteed memory and thread safety without a garbage collector is probably the biggest selling point of Rust. Rust introduces ownership and lifetimes to ensure systems are free of memory-related issues while maintaining high performance.
Humans tend to make mistakes. Developers are not an exception. Especially in this era where computers and software are everywhere. People’s lives, their happiness, everything is being dependent on the technology that we’re building. Mistakes in the critical system can cause disaster and even endanger human life.
Among all different kinds of software errors, memory-related errors are the most complex and unpredictable classes of errors because you cannot easily write tests to catch them. It may stay in the code for years, like a ticking bomb waiting for its hour.
Unlike other system languages which most memory errors are discovered in running time, these memory errors are fundamentally impossible to get in the safe subset of Rust. The compiler flags those issues and forces them to be fixed before the program ever runs.
Rust has been designed to remove the burden of memory safety from our shoulders, allowing us to focus on logical correctness and soundness instead.
Rust is fast. It has no Garbage collector. It compiles to native machine code with no runtime. It is meant to be performed as well as comparable code written in C or C++.
It also features zero-cost abstraction:
What you don’t use, you don’t pay for. And further: What you do use, you couldn’t hand code any better.
Rust also come with concurrency built-in and this is what makes Rust’s ownership system really shines. Developers can choose from a wide variety of paradigms (message passing, shared state, lock-free, purely functional), and Rust will help you avoid common pitfalls. There are more details in this post.
Rust compiler is your biggest enemy and your best friend
Rust compiler is very strict. It does the most significant job to prevent errors in Rust programs. It analyzes the code at compile-time and issues warnings, if the code does not follow memory management rules or lifetime annotations correctly. This makes Rust a little bit hard to write but it is extremely satisfying once it compiles.
You can pair program with the compiler and be sure to have crafted a solid application afterward. It teaches you how to write better program even in other languages.
Rust provides decent tooling to ease the development:
If the compiler is bootstrapped, it is likely to be stable enough to be useful on some other code.
If the compiler developers are using Rust everyday, they are likely to have improved it to the point where it is usable (even if buggy). It is a non-trivial test of the language being compiled, and as such is a form of dogfooding.
Almost everything. Backend, frontend, library, embedded system, OS, CLI tool and etc. Rust empowering every developers to build robust system with confidence.
Of course there are a lot more companies are using Rust in production, you can check here.
Rust is not easy to learn. There are easier languages to learn, but Rust teaches you how to think properly and this is the knowledge which also applicable in other languages. Even you didn’t expect to write a single line of Rust code, I suggest you to take a look on Rust. It is exciting.
If you’re planning to learn a new language, why don’t just give Rust a try? With the release of Rust 2018, it’s never been easier to get started.
“Now is a great time to learn Rust because the 2018 Edition, just released December 6th (2018), has a lot of improvements to the idioms of the language to make Rust more ergonomic to read and write,” says Nichols(Co-author of “The Rust Programming Langauge”).
You can start with "The book". In my opinion, this is the best learning material I’ve seen of any language from the official team.
Other great resources:
I can’t cover all the awesome features that Rust provided. If you’re interested to learn more about Rust, please give it a shot. I hope you enjoy it.
Currently I’m working on a new product in Rust as well as my web framework, Obsidian, hopefully they will be released very soon.