> Const correctness is a beautiful concept and quite unique to C++ (some other languages tried, but nothing). It serves as a contract between those who define the interface and those who use it.
To which I disagree. Rust also has the concept of const correctness because it is heavily inspired by C++. Moreover, Rust's constness behaves far better than C++. To be specific:
* In Rust, variables are immutable (const) by default, declared by "let". To make a variable mutable, you need to write "let mut", which takes more effort. By contrast, C/C++ variables are mutable by default, but made immutable by adding "const". So in Rust, the safer behavior takes less code.
* The Rust compiler checks for mutable variables that don't need to be mutable (e.g. never reassigned, never calling any mutable method), and gives you warning messages to nudge you to remove the unnecessary "mut". I don't recall C/C++ compilers offering this help.
I am not saying you are wrong because I do not know Rust but it appears you only consider variables in your case and not cont parameters for methods and cont methods. The const keyword is used for different things in c++ not like let in other languages that is used only for variable declarations. I apologize if I misunderstood your point.
Good point - by dwelling on variables, I failed respond to the article on the precise topic. Now I'll illustrate const methods and parameters as per your suggestion.
Rust treats parameters identically to local variables, since they are just local variables. All rules that apply to variables also apply to all function arguments (including `this`/`self`).
> Const correctness is a beautiful concept and quite unique to C++ (some other languages tried, but nothing). It serves as a contract between those who define the interface and those who use it.
To which I disagree. Rust also has the concept of const correctness because it is heavily inspired by C++. Moreover, Rust's constness behaves far better than C++. To be specific:
* In Rust, variables are immutable (const) by default, declared by "let". To make a variable mutable, you need to write "let mut", which takes more effort. By contrast, C/C++ variables are mutable by default, but made immutable by adding "const". So in Rust, the safer behavior takes less code.
* The Rust compiler checks for mutable variables that don't need to be mutable (e.g. never reassigned, never calling any mutable method), and gives you warning messages to nudge you to remove the unnecessary "mut". I don't recall C/C++ compilers offering this help.