Should we have a keyword to specify self is mutable in function signatures #409
Replies: 2 comments
-
I'm leaning towards not doing this, but I'll leave this hear until we reach this milestone. In top-level scripts, I'm just leaving the behaviour as-is anyway because I'm assuming most variables need to be mutable there. |
Beta Was this translation helpful? Give feedback.
-
After giving this a bit more thought, I think it's best to not compromise with the philosophy of Mamba. |
Beta Was this translation helpful? Give feedback.
-
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 add
fin
.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 because
self
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:
The main reasoning is that:
fin
is used in contexts where mutability is generally the defaultmut
is used in contexts where non-mutability is generally the defaultHowever, 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
Beta Was this translation helpful? Give feedback.
All reactions