rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.2k stars 12.7k forks source link

Rename “mutable reference” to “mutative reference” #118631

Closed ropery closed 11 months ago

ropery commented 11 months ago

Location

Throughout the documentation.

Summary

The term mutable reference is misleading. It’s not the reference that is mutable, but it denotes a reference through which the value referred to may be changed. A better term would be mutational reference.

Granted, there are instances of similar “illogical” usage in some Englishes: the British have “poor relief”, Aussies say “aged care”, and “disabled parking” is current broadly. Those appear to be shorthand forms: adj. n. = n. for the adj. Even this illogical logic would not justify “mutable reference”: if we take it to mean “reference to a mutable”, we wouldn’t be distinguishing it from a shared reference to the same mutable value. We want the term to make sense as plainly as “borrowed as mutable”. My proposal for a straightforward replacement is “mutational reference”.

PS Apologies if this is the wrong place to post this. Please correct me.

PPS I’m new to Rust, so there’s a chance I may have misunderstood the concept completely. But I guess it’s also why a nonsensical term would stand out to me so much, as I’m not inured to it.

PPPS I know, I know, this is too entrenched, a forlorn hope, herculean, surely! Worth a try!

ChrisDenton commented 11 months ago

It's a bit of a misnomer in either case. The key difference is shared vs. exclusive access. But too late to change that now though.

ropery commented 11 months ago

It's a bit of a misnomer in either case.

Hi @ChrisDenton, can you tell me why you think “mutational reference” would also be a misnomer?

The key difference is shared vs. exclusive access.

Yes, exclusive reference (mirroring shared reference) would correctly reflect that key fact. But I argue that, since exclusive access is a consequence of this being a write-capable (as opposed to read-only) reference, the primary name for it should reflect that primary fact, as “mutable reference” clumsily does.

But too late to change that now though.

If not in one fell swoop, we could first add mutational reference as an alternative term, and gradually deprecate the old term.

Edit: Which is better, mutational or mutative?

SkiFire13 commented 11 months ago

But I argue that, since exclusive access is a consequence of this being a write-capable

Why would it be a consequence? It isn't, in fact it's the opposite, allowing writes without other restrictions is possible because of exclusivity. But you don't necessarily need exclusivity to have write capabilities, consider for example &Cell<T>.

The fact that they are commonly called mutable references (or any other name derived from mutation) misguides people that come from C/C++ to think they can create aliasing exclusive references as long as they don't use them at the same time, which would be true if you only care about mutations, but it's immediate UB due to the exclusive nature of them.

Edit: Which is better, mutational or mutative?

As a non-native speaker, both would confuse me.

ropery commented 11 months ago

I don’t know enough Rust to address the suggestion (as I read it) that shared references can have write capabilities of some sort. If, however, it remains desirable a &mut ref should have a name (perhaps one of several) reflecting the mut part, I will try to dilate a bit on the differences between mutable, mutative, and mutational.

The suffix -ive means “pertaining to, tending to; doing, serving to do”; -al “of, like, related to, pertaining to”. The -able suffix is more complicated sometimes (e.g., sensible, depending on this sense being a verb or noun) but in the case of mutable, it’s unambiguous. For comparison, let’s look at adjective forms of generate:

and common collocations of adjective forms of correct:

and this random quote:

His rights in us are both natural and acquired; they are redemptional rights, the recovered rights of the infinite [redemptive] love which in Jesus Christ saved mankind [(who are redemptible or redeemable)] by extreme sacrifice from the doom of death eternal.

I think mutative (“serving to mutate” (mutate as transitive verb, “cause to undergo mutation”)) is less vague than mutational (“pertaining to mutation”), and so should be preferred.

(For completeness, mutationable could be coined, on the pattern of actionable, but I doubt many would find that palatable.)

ChrisDenton commented 11 months ago

I don’t know enough Rust to address the suggestion (as I read it) that shared references can have write capabilities of some sort.

A very simple illustration:

use std::cell::Cell;
let value = Cell::new(100);
let cell_ref = &value;
cell_ref.set(50);
dbg!(cell_ref); // the value is 50.

(playground link)

ropery commented 11 months ago

A classic case of the exception that proves the rule.

Noratrieb commented 11 months ago

I suggest moving this discussion to https://internals.rust-lang.org instead, which is a lot better suited for discussions like this. Changing the term is not simply a docs change but requires changes all over the place. Closing this, feel free to continue discussion on IRLO.