`const ref T` or `ref const T`?

Renato Athaydes renato at athaydes.com
Thu Aug 15 17:59:59 UTC 2024


On Thursday, 15 August 2024 at 15:20:59 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> On 16/08/2024 3:18 AM, Jonathan M Davis wrote:
>> On Thursday, August 15, 2024 8:56:29 AM MDT Richard (Rikki) 
>> Andrew Cattermole
>> via Digitalmars-d wrote:
>>> On 16/08/2024 2:47 AM, Jonathan M Davis wrote:
>>>> Either way, the person to convince would be Walter, and 
>>>> based on past
>>>> discussions of this sort, I doubt that he'll be convinced, 
>>>> but who knows.
>>>> It can sometimes be quite surprising what he does or doesn't 
>>>> agree with,
>>>> and it's not like he never changes his mind.
>>>
>>> Considering that he allowed the abomination that is return 
>>> and scope
>>> ordering to result in two different attributes, it's worth 
>>> talking with
>>> him about it I'd say!
>> 
>> That is indeed an abomination, and I'd love to see that fixed 
>> (though
>> honestly, I'd love to see DIP 1000 thrown out entirely), but 
>> it's a very
>> different situation from const ref vs ref const. The problem 
>> with
>> return scope vs scope return is that it not only makes the 
>> order matter, but
>> it makes it so that each order means different things. On the 
>> other hand,
>> requiring ref const would be requiring a fixed order when we 
>> have no need to
>> do so, and both orders are currently fine.
>> 
>> - Jonathan M Davis
>
> I'm currently writing up a proposal to replace DIP1000 in its 
> entirety and yeah I got great joy from writing the grammar 
> removal for it 2 hours ago!

I am trying to understand what is currently happening with D, and 
where it is going. It's extremely confusing. I see DIP1000 
mentioned a lot, and was under the impression it had already been 
"accepted"? But now I see it is marked as "superseded"?? By what?

Someone briskly told me to stop using `in` because that's "buggy" 
or something, and I found [a comment from 
2018](https://forum.dlang.org/thread/dkstvxwbcluncgllvypt@forum.dlang.org) (wow, 6 years ago?!) explaining that there's controversy on what that should actually mean (`const` VS `const scope`) and the current docs mention it's just `const` unless you use the `-preview=in` flag (so I guess it did end up meaning `const scope` but it's still hidden behind a flag, perhaps temporarily??)... and does `scope` do what DIP1000 said it would or has it changed? If it does, DIP1000 was then only "partially" accepted??

I also saw somewhere that pointers should not be used in D 
anymore in most cases because `ref` is a better and safer 
alternative... is that a correct assessment? If we want to write 
code that benefits from the goals of DIP1000, do we currently 
need to know the exact meaning of `return ref scope` VS `ref 
return scope` and the many other variants with `const`, `auto` 
and others? This seems really error prone and difficult to 
understand, no? This kind of makes Rust look simple.


More information about the Digitalmars-d mailing list