Description
The idea of shortening let mut
to var
has been discussed many times before, and the general consensus always ends up being that it is not a good idea. I would like to propose something a bit different, so please hear me out.
I propose that instead of aliasing var
to let mut
, we instead just make mut
expand into let mut
when in the context of a variable declaration. For example:
let mut foo = 12;
// is identical to
mut foo = 12;
This solves the problems (readability, more concise) that people have with let mut
, whilst not causing the issues that people have (pattern matching and consistancy).
The most common issue people have with aliasing var
to let mut
is that it doesn't fit well with patterns, like let (x, mut y) = ...
. However, mut
gets rid of this problem, because you wouldn't write let mut (x, mut y)
if you were trying to pattern match, so why would someone want to write mut (x, mut y)
? You wouldn't do that, and it wouldn't compile.
This would be optional, of course. let mut x = 1
would still work fine, and people would just have to option of removing the let
to let it be implied.
There are a lot of other abbreviations used in rust (fn
, mod
, pub
) that all serve the purpose of writing less. It just doesn't feel right that one of the most commonly used keywords is so long.
❤️🦀