Explicitly saying ref or out when invoking a function

Steven Schveighoffer schveiguy at yahoo.com
Tue Aug 11 13:27:43 PDT 2009


On Tue, 11 Aug 2009 15:47:15 -0400, Michiel Helvensteijn  
<m.helvensteijn.remove at gmail.com> wrote:

> Ary Borenszweig wrote:
>
>> In C# when you define a function that takes an out or ref parameter,
>> when invoking that function you must also specify ref or out. For  
>> example:
>>
>> void fun(ref uint x, double y);
>>
>> uint a = 1;
>> double b = 2;
>> fun(ref a, b);
>>
>> What do you think?
>
> I see what you mean, however:
>
> -----
>
> swap(ref a, ref b);

I tend to agree with this, most of the time, your function name hints at  
what is a reference and what is not.

If this is implemented, then a ref const argument should not require a ref  
keyword to call (since there is no way to change it in the function).

One thing about C# is that most everything is pass-by-reference anyways,  
so the ref and out, keywords are not common.  However, in D I think the  
tendency to lean towards value types, and indicate pass by ref for  
performance means that code will get a lot uglier if this were to be  
implemented.  This is just a gut feeling, I haven't done a true study.

-Steve



More information about the Digitalmars-d mailing list