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. 