Thread overview
Second Draft: ref for Variable Declarations
May 02
https://github.com/WalterBright/documents/blob/01291980cbfd80b85575fc6f8ba44d0d433cd4f8/varRef.md

This is pretty much done.
May 03
On Friday, 3 May 2024 at 03:43:39 UTC, Walter Bright wrote:
> https://github.com/WalterBright/documents/blob/01291980cbfd80b85575fc6f8ba44d0d433cd4f8/varRef.md
>
> This is pretty much done.

This DIP has an implementation, you should link to it.

Most of the `Rationale` section is exposition (describing existing behaviour), not rationale. The last line of the rationale is parenthetical to the abstract, not the rationale. The actual rationale (comments about the use of `ref` in `foreach`), should be written as stating the upside of the use of such `ref`s, not that no downsides exist. You should give examples as to times when you felt the feature should exist (or link to them elsewhere in the document) rather than assert they exist (with no evidence).

You should include a diff of the relevant parts of there grammar (where appropriate).

Your example that purports to show the utility of the new feature is already accomplishable by `alias`
```d
void pop87(int line, const(char)* file)
{
    alias g = global87;
    // ... use `g`
```
as noted by Rikki in the previous thread.

May 03
On 03/05/2024 4:19 PM, Nicholas Wilson wrote:
> Your example that purports to show the utility of the new feature is already accomplishable by |alias|
> 
> |void pop87(int line, const(char)* file) { alias g = global87; // ... use `g` |
> 
> as noted by Rikki in the previous thread.

I didn't know that it worked with same scope and was counter proposing expansion.

But yeah it totally does.

```d
import std;

int global;

void main()
{
    int var;
    alias g = global;
    alias v = var;

    writeln(g, v); // 00
}
```
May 03
On 5/2/2024 9:19 PM, Nicholas Wilson wrote:
> Your example that purports to show the utility of the new feature is already accomplishable by `alias`
> ```d
> void pop87(int line, const(char)* file)
> {
>      alias g = global87;
>      // ... use `g`
> ```

Not exactly. Accessing global variables takes a varying number of instructions depending on the memory model. Using a ref variable makes it a simple pointer. An alias is fundamentally different, although in trivial cases they can appear to be the same.

There are three ways to refer to a value

1. by value
2. by reference
3. by name

Alias is by name, you'll see it also in ref, alias, and value parameters to function templates.


May 03
On 5/2/2024 9:19 PM, Nicholas Wilson wrote:
> On Friday, 3 May 2024 at 03:43:39 UTC, Walter Bright wrote:
>> https://github.com/WalterBright/documents/blob/01291980cbfd80b85575fc6f8ba44d0d433cd4f8/varRef.md
>>
>> This is pretty much done.
> 
> This DIP has an implementation, you should link to it.

Ok.


> Most of the `Rationale` section is exposition (describing existing behaviour), not rationale. The last line of the rationale is parenthetical to the abstract, not the rationale. The actual rationale (comments about the use of `ref` in `foreach`), should be written as stating the upside of the use of such `ref`s, not that no downsides exist. You should give examples as to times when you felt the feature should exist (or link to them elsewhere in the document) rather than assert they exist (with no evidence).

You're right, but what is the point? Aren't they rather obvious? After all, we all have experience with ref parameters in D, and ref variables in foreach, that have the same purpose. Refs are well known and exist in other languages, like C++ and C#. Is there any controversy here? What refs do and what they're good for is completely constrained by the behavior of the existing uses of ref.


> You should include a diff of the relevant parts of there grammar (where appropriate).

There are no changes to the grammar. Ref locals were previously rejected in the semantic pass.

May 03
On Friday, 3 May 2024 at 07:57:34 UTC, Walter Bright wrote:
> Not exactly. Accessing global variables takes a varying number of instructions depending on the memory model. Using a ref variable makes it a simple pointer. An alias is fundamentally different, although in trivial cases they can appear to be the same.
>
> There are three ways to refer to a value
>
> 1. by value
> 2. by reference
> 3. by name
>
> Alias is by name, you'll see it also in ref, alias, and value parameters to function templates.

Then you should explain that in the DIP and use that to argue by access by name is undesirable compared to by ref (in whatever cases you add to prosecute the case for the DIP). All the DIP says at the moment is that "its can be done like this", it cites no additional logic as to why that is superior to option that currently work already in a syntactically analogous way.
May 03
On Friday, 3 May 2024 at 08:08:13 UTC, Walter Bright wrote:
>> You should include a diff of the relevant parts of there grammar (where appropriate).
>
> There are no changes to the grammar. Ref locals were previously rejected in the semantic pass.

Then you should note in the DIP that no changes to the grammar are needed.

May 04
On Friday, 3 May 2024 at 08:59:19 UTC, Nicholas Wilson wrote:
> Then you should note in the DIP that no changes to the grammar are needed.

It's the first sentence of the description:
https://github.com/WalterBright/documents/blob/01291980cbfd80b85575fc6f8ba44d0d433cd4f8/varRef.md#description