www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - On Variable References

reply "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> writes:
Why doesn't D allow declarations such as

     int x;
     auto ref xr;

?

What is so fundamentally bad about this compared to foreach 
variables and function arguments passed by reference?

Will Walters latest commits regarding

http://wiki.dlang.org/DIP25

change this matter?
Jan 21 2015
parent reply "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> writes:
On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw wrote:
     int x;
     auto ref xr;
Correction: I, of course mean, int x = 42; auto ref xr = x;
Jan 21 2015
parent reply "Meta" <jared771 gmail.com> writes:
On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw wrote:
 On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw 
 wrote:
    int x;
    auto ref xr;
Correction: I, of course mean, int x = 42; auto ref xr = x;
Walter is strongly against adding references a la C++ to D, as he believes they are too complicated and bug prone. He's made several posts on this, but I can't find them now.
Jan 21 2015
next sibling parent =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote:
 Walter is strongly against adding references a la C++ to D, as 
 he believes they are too complicated and bug prone. He's made 
 several posts on this, but I can't find them now.
It would be interesting to read about how Walter thinks here :) Thanks anyway.
Jan 21 2015
prev sibling next sibling parent "weaselcat" <weaselcat gmail.com> writes:
On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote:
 On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw 
 wrote:
 On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw 
 wrote:
   int x;
   auto ref xr;
Correction: I, of course mean, int x = 42; auto ref xr = x;
Walter is strongly against adding references a la C++ to D, as he believes they are too complicated and bug prone. He's made several posts on this, but I can't find them now.
Artificial constraints like this and no default constructor implementations for structs makes D annoying to use for programming that relies heavily on deterministic resource management tbh.
Jan 21 2015
prev sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote:
 On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw 
 wrote:
 On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw 
 wrote:
   int x;
   auto ref xr;
Correction: I, of course mean, int x = 42; auto ref xr = x;
Walter is strongly against adding references a la C++ to D, as he believes they are too complicated and bug prone. He's made several posts on this, but I can't find them now.
In DIP69, he himself proposed `ref` locals. However, that's not the same as "references a la C++".
Jan 22 2015
parent "Meta" <jared771 gmail.com> writes:
On Thursday, 22 January 2015 at 14:52:26 UTC, Marc Schütz wrote:
 On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote:
 On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw 
 wrote:
 On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw 
 wrote:
  int x;
  auto ref xr;
Correction: I, of course mean, int x = 42; auto ref xr = x;
Walter is strongly against adding references a la C++ to D, as he believes they are too complicated and bug prone. He's made several posts on this, but I can't find them now.
In DIP69, he himself proposed `ref` locals. However, that's not the same as "references a la C++".
Hmm, it seems that he did. If D were to allow creating ref variables, wouldn't D ref be more or less like in C++, then? Aside from the weirder things like T&& and such.
Jan 22 2015