Should out/ref parameters require the caller to specify out/ref like in C#?

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Sun May 28 15:23:00 PDT 2017


On Sunday, 28 May 2017 at 22:18:01 UTC, Stanislav Blinov wrote:
> On Sunday, 28 May 2017 at 22:03:48 UTC, Stefan Koch wrote:
>> On Sunday, 28 May 2017 at 17:54:30 UTC, WebFreak001 wrote:
>>> Imagine you wrote a function
>>>
>>> void foo(ref int a) {
>>>   if (std.random.uniform(0, 10) == 0)
>>>     a = 0;
>>>   // Actual code doing something
>>> }
>>>
>>> [...]
>>
>> Syntax wise we could force you to say foo(&something).
>> Which fits perfectly in the existing pointer syntax.
>
> No it does not, because then this becomes ambiguous:
>
> foo(ref int a);
> foo(int* b);
>
> ...and furthermore, what would we do with this:
>
> void foo1(T)(auto ref T a) { foo2(a); }
> void foo2(T)(auto ref T a) { /*...*/ }
>
> ?

Personally I stay away from ref precisely because of it's silent 
caller syntax.


More information about the Digitalmars-d mailing list