Why would getting rid of *
make the language more clear or more clean?
.
is for member access. *
is for dereferencing. When you're doing member access, you often need to dereference first, so .
does a little bit of magic to make that more ergonomic. It does not mean that every use of *
can be eliminated (which seems to be what you're talking about).
When you're doing other things, you often do not need to dereference first. Add<u64>
is implemented for both u64
and &u64
, and while in the case of &1 + 2
it doesn't really matter which is picked, it does matter that the compiler can pick one unambiguously and in a way that will not confuse people. Sure, it would be possible to come up with some half-baked rules for when dereferencing happens automatically, but then we'd be stuck with them forever. Another weird language quirk for students to be baffled by 20 years down the line, like how C++ has a dozen rules for when the language automatically supplies different member functions if you don't write them.
I personally don't want to have to remember a dozen rules for when the language automatically dereferences things. Deref
is already pretty magical, to be honest, but the magic is contained to member access with .
(autoderef) and coercion sites (deref coercion). I'm not excited about adding another place where Deref
is magical, with its own set of rules that isn't exactly the same as either of the other two. People already get confused between autoderef and deref coercion even though they're basically completely separate mechanisms.
When you do get tripped up, the solution is usually obvious, like in your assert_eq
example: you have an i32
and a pointer-to-i32
, so you dereference the pointer to get an i32
and compare them. No ad-hoc rules, very little magic, just simple-minded, self-evident, clean code. If Rust were trying to dereference stuff to make things easier for you, and it happened to dereference something you didn't mean to dereference, that would lead to confusion and messy code.
That's my opinion. You may feel free to disagree, think that removing *
(even in a subset of cases where it's currently needed) would make the language cleaner. I've given my argument for why I think it would have the opposite effect. But we're both talking about abstracts. If you think there's a way to implement auto-deref for operators that aren't .
, and it wouldn't make the language unnecessarily more complex and harder to understand, please share. I'm open to changing my mind.