Using func mutate(self: inout Self)
for this purpose is a Clever Trickā¢, which I think in the end is a reason not to use it.
It formalizes (or perhaps āblessesā) the idea of an invisible first parameter, which is not currently part of the conceptual apparatus of instance functions. (Yes, I know that currying is possible, but no one is trying to sell currying as a way to understand the Swift language, AFAICT.) Itās also redundant, leading to several suggestions already to remove the non-load-bearing part of the trick: : Self
.
In regard to the dualism issue (e.g. mutating
vs. inout
), it might be convenient to decide to collapse all future pairs of this kind into a single keyword, but it leaves an unsolved problem. The mutating
keyword applies to the function; the inout
keyword parameter applies to a value (such as self
). Collapsing these into a single keyword is just going to smear the concept in ways that donāt help anyone.
Putting aside brevity issues, one possible way forward is to forgo the function-specific keyword, and have just one keyword syntax that is explicit that it applies to self
, say inout self
. Forgoing the initial parameter ātrickā too, then I think there are 3 possible spellings:
-
inout self func mutate()
-
func inout self mutate()
-
func mutate() inout self
I donāt see much value in #2, and I just mention it for completeness.
#1 seems pretty natural, since weāre just trading a function-modifying keyword (mutating
) for a keyword pair. The downside here is that weāre deepening the snowdrift of keywords piling up at the front of declarations.
#3 seems better to me, because weāve already committed that piece of syntax real estate to keywords like throws
and async
that modify how the function behaves without writing out the behavior somewhere else in the declaration.
Note that Iām not contemplating the briefer func mutate() inout
, for the reason given above ā that this modifies the function not the self
, and I think thatās too ambiguous an approach. Also, Iām aware that using 2 words where one would seem to do is going to be unpalatable to some. However, all of the suggestions made so far are unpalatable to some, so I donāt feel I need to hold back for that reason.