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

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Mon May 29 01:40:27 PDT 2017


Nick Sabalausky (Abscissa) wrote:

> In response to any claim that this isn't a real problem in practice, I 
> submit the possibility that, if it indeed isn't a real problem, maybe 
> that's *because* of people (like Stefan and ketmar) simply avoiding the 
> feature entirely so that it *doesn't* become a problem.

exactly! you can include Adam here too, btw. we all prefer to use pointer 
args exactly to avoid *the* *problem*. so it is not a problem for us 
anymore... but we aren't solved it, we simply cheated. basically, my only 
`ref` usage is `in auto ref` (which is not a "real" ref anyway, as argument 
cannot be changed).

side note: also, with pointers i can do `void foo (int a, bool* res=null) 
{...}`. not a big deal: one can always create set of overloads to get the 
same effect with ref, but -- less typing! ;-)

yet i must say that using pointers in a code where they should be 
references makes me... nervous. it just doesn't feel right. but meh, i'll 
trade that (and safety, 'cause `&` is unsafe) for "call site ref indicator".

that's why i don't bother writing @safe code, btw: in one or another way i 
will be forced to hack aroung @safe restrictions, so no reason to start 
that dance at all. (or just mark the whole thing as @trusted and hope for 
the best)


More information about the Digitalmars-d mailing list