Closed ghost closed 1 year ago
Hi,
Yes, the current syntax is let mut
for define to mutable variables and it's may long for you and many peoples. But it's actually not long much, there is four keystroke for let
keyword and whitespace. Is this shorthand really necessary? I think no.
Also the let
keyword says "there is a variable definition", so semantic is let
says "it's a variable" and mut
says "this variable is mutable". In the future, the mut
keyword can be used for many definition or something like that. So, mut a = 10
is ok instead of let mut a = 10
now. But there may be various semantic changes in the future, in this situation this acronym doesn't seem clean enough in terms of readability. Also the currently is pretty clear syntactically and semantically.
Thanks for your contribution.
The word 'variable' per definition means changing state, which I guess has some implications with 'mut' or 'let mut'. It is tautological to say mut or let mut :) Anyway, Rust introduced this logic, and it is up to us to figure this out. let/var? imm/mut ?
edit: let keyword and it's origin: https://en.wikipedia.org/wiki/Let_expression
Variables are immutable by default. So you can't this:
let a = 10
a += 20 // Compiler error
The mut
keyword makes your variable mutable.
So you can now this:
let mut a = 10
a += 20
You can see more information about mutability here.
Kotlin uses val
for immutable and var
for mutable variables.
Which also makes sense:
val -> a value
is set and cannot be changed.
var -> a variable
is defined but in the future its value can vary, hence variable.
Kotlin uses
val
for immutable andvar
for mutable variables. Which also makes sense: val -> avalue
is set and cannot be changed. var -> avariable
is defined but in the future its value can vary, hence variable.
This could be a good change. But it increases the number of keywords. The mut
keyword is not only used in variables. For example, you use the keyword mut
for interior mutability. However, the mut
keyword specifically indicates which variables in foreach iterations and multi-let declarations are mutable. Such a change would require revising many other designs and seems likely to add further confusion.
Such a change requires updating a lot of code and resources. Also, when looking at the entire design, they seem to be in harmony. However, the mut
keyword is also a good reference to mutability for readability purposes. I don't find this change logical because it seems like it could cost more on different topics while avoiding the cost of writing an extra keyword.
Detailed description
I think it would make more sense to have a short identifier for mutability.
Context
Less typing and more coherent syntax.
Possible implementation
No response
Additional information
No response