My go-to programming languages are C/C++ for numerical computations and data processing, C# for Windows GUI applications, and Python for quick scripts and machine learning. Nevertheless I decided to take a look at Rust, as it was recommended to me by a customer and several other sources. And maybe Rust is worth the effort for you, too.
Why you should consider Rust
- Safety is usually cited as the main advantage of Rust. One could in fact consider it an answer to the lenient approach C/C++ takes to memory management. If Rust code compiles, it is very unlikely to produce segmentation faults at runtime. Error checking is an essential part of Rust, at least reminding the coder where things could go wrong and forcing him or her to deal with it in advance.
- Being a compiled language without garbage collection, Rust is on-par with C/C++ in terms of speed. Speed is actually one my main gripes with Python, so it’s nice to see that this is not an issue with Rust.
- Rust uses Cargo as package (called crates) manager and build system. All dependencies are specified in a simple text file and automatically downloaded during the build process. This is so much better than dealing with external dependencies in C++ (I have a huge dislike for CMake and actually use handcrafted Makefiles under Linux) and in my opinion even beats pip/conda, which can struggle at times.
- While Rust does support object orientation, it does not force it upon you (looking at you, Java). It does rather feel quite compact and modular, letting you do a lot with just a few data types, structs, and enums.
And why it might not be the right language for you
- Rust’s safety does of course come at a price. To be safe requires being strict, and all the error checking can be tedious at times. As a result, Rust is less accessible than Python an would not be my #1 for throwing together a small script or teaching someone how to code.
- Despite increasing popularity, the software ecosystem of Rust is not as large as that of C/C++ or Python. Some libraries might not be available or not have the full functionality, especially in niche domains like geographic information.
Online resources
If you’re willing to give Rust a try, here are some resources that can help you get started:
- The Rust Programming Language, usually referred to simple as the book. It is a complete introduction to the core concepts of Rust. A printed version is available from No Starch Press.
- Crates.io is the central registry for Rust crates (packages/libraries).
- You can write Rust code in a text editor (I use Notepad++ under Windows), but you’ll probably want to use an IDE like Visual Studio Code instead. This community post explains how to set up the required extensions, but it is a bit outdated, mentioning some deprecated extensions. Alternative extensions are suggested by VS Code itself. The VS Code documentation also has a page on the subject.
- The Rust Standard Library documentation.
- Rust by Example, a collection of Rust code examples that illustrate many of Rust’s concepts and standard library functions.
- The Rust Cookbook is a collection of examples for solving common programming tasks using the Rust ecosystem.