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

Dukc via Digitalmars-d digitalmars-d at puremagic.com
Mon May 29 00:39:40 PDT 2017


On Sunday, 28 May 2017 at 17:54:30 UTC, WebFreak001 wrote:
> Should the language spec say that those functions should get 
> called with `foo(ref input);` so that surprises like this where 
> the user doesn't check the docs/implementation can't happen 
> (like in C#)?

I think it's mostly about good taste on what you define functions 
to take as ref input. I have a feeling the present way is not a 
big problem in practice because it is intuitive somehow. Besides, 
member functions mutate their class/struct anyway, and we don't 
want to lose our ability to call extension funcions with same 
syntax as member ones.

Same thing as with struct/class separation: in principle it 
sounds pointless that whether used by value or by ref has to be 
defined with the type, but it somehow just works intuitively in 
practice. (My personal experience. Don't know if others feel the 
same way)

But what would be worth a consideration, is that perhaps one 
should be allowed to pass rvalues as reference with something 
like this? According to TDPL, ref arguments do not take rvalues 
to prevent bugs where you accidently copy something before 
passing it, and that's a good rationale. But shouldn't it still 
be allowed explicitly?



More information about the Digitalmars-d mailing list