Release D 2.094.0

Mathias LANG geod24 at gmail.com
Thu Oct 1 17:29:56 UTC 2020


On Thursday, 1 October 2020 at 16:47:37 UTC, Meta wrote:
>
> This seems ridiculous to me. We now have ANOTHER way of asking 
> the compiler to choose for us whether to pass by ref or by 
> value, completely mutually exclusive of auto ref. Where was the 
> DIP (apologies if I just didn't see it)? Did Walter approve 
> this? How do we explain the difference between in and auto ref 
> with (as Andrei would say) a straight face?

Yes we have a 3rd way. Because `auto ref` just doesn't cut it for 
most usages, and `-preview=rvaluerefparam` never worked.

You can have a look at the full discussion in the PR that 
introduced it (dmd#11000).
I try to summarize a few arguments in favor of it here: 
https://github.com/dlang/dmd/pull/11000#issuecomment-674498704

As you can see from the discussion, it's not really something 
that was quickly merged, but the results of months of work. So 
while it might seems "ridiculous" to you, I'd appreciate if you 
could take the time to read through the discussion, as well as 
taking a look at Herb Sutter's presentation which was linked.

The key takeaway from that presentation is that instead of having 
the users specify *how* to pass the parameter, they should 
specify what is the parameter's semantic. In our case, input 
(in), output (out), or input/output (ref).

I'm not aware of a situation where you want to use `auto ref` on 
a parameter without `const` (or `const` semantic), because if you 
intend to modify the parameter, you need to be sure whether it's 
`ref` or not. I'm aware some people use it for forwarding but 
this has its own set of problem.


More information about the Digitalmars-d-announce mailing list