Closed WhiteBlackGoose closed 2 years ago
Mutable and immutable variable declarations should definitely be differentiated.
If we agree on issue #7, we should definitely take some inspiration from Rust in this case. Having var
and val
makes it way too easy to just get var
into muscle memory and use it all the time. Having an explicit mutability modifier could really benefit here (mut var
?).
As much as I don't like to rely on heritage behavior, I think the classic =
, +=
and friends are well-established enough to keep them. Things like <-
are really annoying to type out on some keyboard layouts and providing sensible compound versions would be harder.
Having var and val makes it way too easy to just get var into muscle memory and use it all the time.
This is not the impression I got workign in Kotlin tbh. I write val
without even considering otherwise unless I really need var
. And the compiler and the IDE will definitely let you know if you misused var
.
I agree with var
as variable and val
as value, it's just simple and concise. Other languages let
or mut
just adds more confusion.
About val
val
allows to make a readonly field/variable/property. Similar to what Kotlin has. It does not guarantee the structure being readonly, but the value itself is. Syntax:About var
var
is identical to C#'svar
. It is normally highlighted by the editor.Declaration:
Explicit type
Define it after
:
Unresolved
Should we make reassignment more explicit, like this:
or more "usual", like this: