-
Book Overview & Buying
-
Table Of Contents
The Rust Programming Handbook
By :
One of the first concepts you’ll encounter in Rust is how it handles variables, and this reveals a core piece of its design philosophy. In Rust, variables are immutable by default. This might feel different if you’re coming from languages such as Python, JavaScript, C++, or Java, where variables are typically mutable unless you explicitly mark them as constant (e.g., with const or final). Rust flips this convention on its head: you must explicitly opt in to mutability. This design choice is intentional; it encourages a safer programming style by preventing accidental or unintended changes to a variable’s value, which is a common source of bugs.
This emphasis on immutability makes your code easier to reason about, as you know that most variables won’t change their value after being initialized. However, Rust is a practical language and understands that mutability is often necessary. For those situations, it provides...