<div dir="ltr">On 21 April 2013 06:51, Timon Gehr <span dir="ltr"><<a href="mailto:timon.gehr@gmx.ch" target="_blank">timon.gehr@gmx.ch</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5">On 04/20/2013 05:56 PM, Dicebot wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
You miss quite an important point - DIP36 does not add new feature. It<br>
partially defines existing feature (scope) to replace an existing but<br>
broken solution (auto ref). Nothing new is really added to the language,<br>
only existing stuff better defined.<br>
</blockquote>
<br></div></div>
_New meaning_ is assigned to existing grammar whose original purpose is at most loosely related to the _new_ features.<br>
<br>
I do not think that making 'scope' indicate an rvalue reference is particularly future proof.<br>
</blockquote></div><br></div><div class="gmail_extra" style>That's not what scope does. Scope promises that the variables will not escape the scope. And as such, just happens to make passing a temporary by ref safe.</div>
<div class="gmail_extra" style>It does not implement r-value ref's. It simply allows refs to temporaries to be considered a safe operation.</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>
This DIP is actually likely to solve an important source of problems, consider:</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>void func(const ref matrix m);</div><div class="gmail_extra" style>
<br></div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>func(x.getMatrix()); // compile error!<br></div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>// fu*^&%$ing hell! you piece of &%^#≈¿$!</div>
<div class="gmail_extra" style>// ...</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>matrix temp = x.getMatrix();</div><div class="gmail_extra" style>func(temp); // no more compile error! (but equally unsafe/dangerous)</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>In this example, the 'solution', which is what everybody does right now, is exactly as unsafe as the attempted call with the r-value.</div>
<div class="gmail_extra" style>ref, as in the language right now, is a fundamentally unsafe operation... and not only is it technically unsafe, a programmer can't even know if it is practically unsafe or not.</div><div class="gmail_extra" style>
Since they have a habit of using this hack, they may unknowingly use it in a call site where it's not *practically* safe to do it. They can't know, and by habit (and frustration) they're trained to use this hack everywhere.</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>With 'scope ref' (or 'in ref'), the programmer now has a guide to say whether it's safe to pass a temporary or not. In the future, if the function does not receive scope ref, perhaps the programmer will start to presume that it is NOT safe to pass a temporary, and stop doing so via the current local-variable hack.</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>scope was always intended to implement this promise as far as I'm lead to believe(?).</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>
<Side rant></div><div class="gmail_extra" style>In my experience showing D to new people, this is the #1 complaint. It's the first one that comes up, every time (which really doesn't help with first impressions), and I'm fairly sure every single person I've introduced to D has complained about this.</div>
<div class="gmail_extra" style>It's kind of embarrassing when I'm saying that D is really cool, and then I have to start making excuses and apologising for this, and assure them that it's a known issue, and it'll be fixed one day.</div>
</div>