Closed JSAbrahams closed 1 year ago
I'm leaning towards not doing this, but I'll leave this hear until we reach this milestone.
The main reason for not doing this would be that we should in functions stick to the same philosophy as top-level scripts.
My main gripe is that for many applications you don't need everything to be mutable, so having to put fin
constantly in signatures is a bit cumbersome and may lead to it not being used.
In top-level scripts, I'm just leaving the behaviour as-is anyway because I'm assuming most variables need to be mutable there.
We could also use the var
val
system from Kotlin and Scala (?).
Would be a bit sad since I did like that we use def
for everything, which feels more math-like.
Current Issue
Ideally we want in functions to be able to define whether
self
is mutable or not. Currently, the default is that it is mutable, and if we want self to be final then we have to addfin
. E.g:However, by default users will most likely always have
self
be mutable (by not appendingfin
). This is fine, until we have a final variable and try to access its methods. Then, the compiler will constantly throw errors becauseself
will most likely be mutable (even when it needn't be). Instead, we want that self is final by default and only mutable if the user explicitly defines this. This falls along the line of the philosophy of "strict, but as familiar as possible to those coming from Python. So then we would have the following:A few issues here is that:
fin
is used in contexts where mutability is generally the defaultmut
is used in contexts where non-mutability is generally the default However, this may be seen as too much hand-holding. The issue, as I see it, is that in my experience mutability in modern "strict" languages is the exception, and not the other way around.High-level description of the feature
mut
, which may only be used in function signatures.Description of potential implementation