Should I Learn Rust?
March 25th, 2023

This is a very brief no-code post that reviews some cool aspects of the Rust Programming Language, intended to provide insights to those considering learning it. If you already have experience with Rust, I hope this post helps you decide whether you should keep making progress on it or not.

Brief History

Rust began as a personal side project in 2006 by Graydon Hoare, who was a researcher at Mozilla at the time. The main goal behind the language was to create a safe systems programming language, with a big focus on performance.

🍄 The name Rust comes from a group of fungi that according to Graydon are “over-engineered for survival”

In 2009, Mozilla made the decision to officially sponsor Rust due to the shortcomings of existing programming languages, such as C and C++. They wanted to "build a better Firefox and contribute to a better Internet". Finally, on May 15, 2015, the first stable version of Rust was released.

Let's now explore some of the features that define this language.

Memory Safety

Memory safety refers to a program's ability to always use memory pointers that point to valid memory of the correct type and size. An unsafe memory program can cause unwanted failures or produce non-deterministic outputs, which can compromise the reliability of the software.

In languages with a Garbage Collector (e.g. JavaScript💕), memory safety is guaranteed for all data allocated within the language's runtime, as long as the GC implementation is correct. These languages abstract memory as an implementation detail.

In languages that do not have garbage collection like Rust, the compiler must ensure these memory properties through static analysis (such as using the Borrow Checker) or the programmer must manage them carefully at runtime.

Thanks to Rust's ownership model and rules for references and borrowing, correct memory handling is guaranteed by the compiler in all Rust programs that do not use unsafe code.

Performance

There are certain aspects that contribute to the high performance of Rust programs:

  • Primarily, It’s a compiled language. This allows it to implement compile-time optimizations for the final program to consume fewer resources or execute faster.

  • Implements zero-cost abstractions, such as iterators, traits, and smart pointers. Basically high-level structures designed to optimize to straightforward machine code.

  • Supports parallelism and concurrency. Its ownership and borrowing system provides safe and efficient shared mutability, which can be used to implement parallel algorithms and data structures.

  • Optimizes the performance of generic functions by implementing monomorphization, which transforms them into specific type functions at compile time, reducing runtime costs.

In addition to the above topics, not having a Garbage Collector improves the program performance. Garbage Collectors add overhead at runtime because they need to track memory usage (usually by reference counting) to determine when memory can be freed. This increases both memory usage (critical for embedded systems) and CPU usage (important for high-performance software). Additionally, Garbage Collectors are more difficult to control, which can result in unexpected pauses during execution when running or freeing unused resources.

Features

Rust provides various tools that improve the development experience:

  • Cargo: Rust's package manager, which handles Rust package dependencies, compiles packages, creates distributable packages, and uploads them to crates.io, the Rust community package registry.

  • Docs: Cargo's documentation generator ensures that all APIs are documented. You can access it locally via cargo doc and online for public packages via docs.rs.

  • Rustfmt: Rust formatter - GitHub

  • Clippy: Rust linter - GitHub

Finally

Rust combines the safety and performance features of established programming languages with the resources and community of a young language. I would say that if you are interested in developing efficient and reliable applications in a modern language, go for it!

I really appreciate your interest in this, thank you! You can now reward yourself with some funny capybara videos.

References

Subscribe to Brechy
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from Brechy

Skeleton

Skeleton

Skeleton