You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple getters may want to return a mutable reference to a field if the object being accessed is mutable, but an immutable one otherwise. This would cause code duplication, which, although mild for the "simple getter" case, is still duplication, and can be seen in languages like C++ where writing const overloads is a requirement.
I propose a qualifier like mut*, which will declare two methods, one of which is mut and the other isn't, but otherwise with the same body, for example:
def Foo.get_something(self mut*) Bar mut* = ...
when Foo.get_something is called with Foo mut, the result is Bar mut, but if it is instead called with Foo, the result is simply Bar.
I am unsure how far this feature should extend, since i only see a real use case for them in the "self" argument case, so the feature may initially be restricted to only the self argument and the return type, however it is also way too early to say since this is still merely an idea
The text was updated successfully, but these errors were encountered:
Simple getters may want to return a mutable reference to a field if the object being accessed is mutable, but an immutable one otherwise. This would cause code duplication, which, although mild for the "simple getter" case, is still duplication, and can be seen in languages like C++ where writing const overloads is a requirement.
I propose a qualifier like
mut*
, which will declare two methods, one of which is mut and the other isn't, but otherwise with the same body, for example:when
Foo.get_something
is called withFoo mut
, the result isBar mut
, but if it is instead called withFoo
, the result is simplyBar
.I am unsure how far this feature should extend, since i only see a real use case for them in the "self" argument case, so the feature may initially be restricted to only the self argument and the return type, however it is also way too early to say since this is still merely an idea
The text was updated successfully, but these errors were encountered: