small idea

David Piepgrass qwertie256 at gmail.com
Wed Jan 9 08:51:10 PST 2013


On Wednesday, 9 January 2013 at 15:10:47 UTC, bearophile wrote:
> eles:
>
>> void make_a_equal_to_b(??a,!!b); //I give you "b", give me "a"
>
> A saner syntax is just to use the same in/out/inout keywords at 
> the call point, This is essentially what C# does (with one 
> exception for COM):
>
> make_a_equal_to_b(ref a, in b)
>
> This feature was discussed several times in past for D. The 
> advantage is more readability for the code and less surprises. 
> The disadvantages are more typing, some code breakage of D2 
> code (because even if at the beginning it's a warning, and 
> later a deprecation, you will eventually need to enforce it 
> with an error).

The same thing happens every time this is discussed: some people 
insist "ref" and "out" should be REQUIRED or else it should not 
be ALLOWED. Others don't want to break backward compatibility so 
they insist it can't be required. There is no common ground so it 
never gets to the "allowed" stage.

In C++ I actually use call site ref for & params even with no 
checking at all:
#define IN
#define OUT
in fact these are defined in a Microsoft header. I find them 
useful for documentation.

Again, my proposal is that the compiler should allow ref/out and 
not warn when it is missing; if users want a warning/error for 
missing ref/out, they can ask for it per-module with a pragma (or 
something).

> One more small D-specific problem is what to do if the first 
> argument is a ref and you want to use UCFS.

In the past I suggested allowing implicit ref for structs (but 
probably not for classes) with UFCS, because the "this" parameter 
of a member function of a struct is passed by ref already.


More information about the Digitalmars-d mailing list