I propose rust to implement
var keyword as an alias for
let mut. Some might think that’s unnecessary and I respect that, however, I think people who would like to create mutable variables by default without much cognitive thinking deserve that option too.
It would also make rust similar to 99% of language out there that has var being the default for mutable variables.
This is similar to the optional keyword
return found in rust, where you don’t have to use it, but it’s available if you would like to.
The compiler can suggest to turn
let if it’s not necessary.
It would make rust more natural as a programming language similar to most languages.
It’s doesn’t have to be named
var, you can pick another to allow the function.
You might say that having
var would make it confusing; however, Rust already has a similar situation with the
let keywords, where both function as an immutable variable but they are implemented differently.
var keyword can be denied by clippy as well if you would like too, that’s in addition to compiler warning in case the variable isn’t muted similar to
let mut when it’s not necessary to change to
Making every Rust variable declaration immutable by default would greatly affect its adoption rate, it greatly reduces productivity in my opinion. I am certain that having both options(let and var) is the best way to go. I am not familiar with any other language that takes this immutable approach. It makes sense to have parameters immutable by default since people almost never mutate parameters; however, this is not the case with variables, and introducing var or similar keyword would be the solution for this concern. This would increase rust adoption rate in my opinion.