D'oh -- apologies, @ellie20. I think my post does address your suggestion, but in an overly roundabout way.
To put it more explicitly: we want to reserve the names mutate
and borrow
for a third set of accessors that we want to add later, and I'm arguing that these names work best for those.
We know from years of experience that read
and modify
work as names for the coroutine accessors, because we've been using the old _read
and _modify
names for roughly the same accessor semantics. (Granted, I may be overly used to these, as I've been working with them since 2017/18 or so; however I did not ever find difficult to keep them separate.)
The names we give to accessors matters a great deal. I do agree that the names should not be too close to each other; but the names we're proposing (get
/borrow
/read
and set
/mutate
/modify
) aren't synonyms, and that makes them viable.
(Having three separate sets of accessors will definitely be more complicated than our current way, no matter what we name them. However, this seems unavoidable -- for Swift to successfully compete for the space previously filled by C/C++, we need to allow the language to properly model direct access; and this requires separating things that we could previously handle uniformly. Making coroutine accessors a public language feature doesn't really help the competitiveness part; it just resolves the issue that get
/set
aren't enough for noncopyable types. I expect the (far less general) borrow
/mutate
accessors will bring us the (predictable) performance and expressivity that we need.)
The only pair that gives me some pause is mutate
and modify
. These aren't synonyms either, but we've been using these somewhat interchangeably in loose contexts, such as in technical documentation; so using both of them may be stretching it a bit. "Mutate" implies a more fundamental change than "modify"; and that rhymes with the way the planned accessors will work -- but is it too late to separate the terms?
yield get
and yield set
aren't bad naming alternatives, but they feel a bit mismatched/patchy to me. ("yield set" feels particularly weird -- the modify accessor does not at all work like a setter.) However, if using these names helps reserving the borrow
/mutate
names for the upcoming direct accessors, then so be it.
What about yield borrow
and yield mutate
though? I think the coroutine accessors have semantics much closer to those than to get
/set
.
nonmutating
is a indeed valid modifier on the proposed coroutine based modify
accessor; however, consuming read
is not a thing, and should not ever become a thing. (Consuming behavior only makes sense for a get
accessor: consuming get
gives us the semantics we often need when we want to unbox a wrapped value that is noncopyable. consuming read
does not appear to have useful semantics. (Neither does consuming set
, consuming modify
nor consuming mutate
.)
Note that the planned borrow
/mutate
accessors are not expected to support consuming borrow
or nonmutating mutate
, either.