But "let" is already a thing in Kotlin (a scope function in the standard library).
In my experience, in practice "var" are an order of magnitude more rare than "val", so I'd be perfectly fine with "val" vs. "mutable". I wouldn't mind the verbosity - it would gently discourage the use of mutability, while making it very apparent wherever it's actually involved.
> in practice "var" are an order of magnitude more rare than "val"
Or rather, it should be that way. Agreed, and I think because the world has been moving more and more towards functional style over the past decades, I'd predict that the next big language that will make it to the mainstream will likely take the approach "immutability by default".
mut is a nice proposition, I'd certainly consider it if I were to design Kotlin
If a variable is const-declared, I react in exactly the same way and know that I don't have to look for further uses, which I find very valuable.
I even do stuff like this, which might be extreme but I find it coherent and nice:
void * allocate_and_fill(size_t size, unsigned char x)
{
void * const p = malloc(size);
if (p != NULL)
memset(p, x, size);
return p;
}
The above const-declares the local pointer p, so that it can never be intentionally clobbered inside the function, which would leak the memory. Since it's the pointer itself that is constant, not the data being pointed at, there is no problem in modifying that memory, and the return value is not const-declared in any way.Syntax wise the languages are quite similar (before we get to type systems).
At first I really hated how similar the keywords were (something like let/const seemed preferable).
After a few years of Scala you get used to it.
In fact val somehow feels "nice" and var feels "dirty" so you avoid it as much as possible.
This is a long-debunked myth. See e.g. https://docs.microsoft.com/en-us/typography/develop/word-rec...
Though note that val and var are more similar in terms of their letter content than they are in terms of their word shape.