<div class="gmail_quote">On 12 May 2012 14:03, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Saturday, May 12, 2012 13:39:54 Manu wrote:<br>
> Awesome, although it doesn't end there. Local references are also very<br>
> important.<br>
<br>
</div>Never going to happen. Walter doesn't like them (they also cause issues with<br>
the proposal to let ref take rvalues in D IMHO), but I don't remember the<br>
details. Regardless, I'd be shocked if they were ever introduced into D.<br></blockquote><div><br></div><div>So what's the work around then?</div><div>Using pointers pollute your usage with pointer assignment problems, and leads to many redundant instances of &, *, and parentheses all over the place.</div>
<div><br></div><div><div>Another scenario to consider:</div><div>given: ref X someFunc();</div><div><br></div><div>ref X t = someFunc(); // fail</div><div><br></div><div>Without ref locals, there is no way to hold a local reference to something returned by a function, which defeats the purpose...</div>
<div>And if ref is not a type constructor, auto and templates will never work properly either.</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">Well, while I'm sure that your use cases are very important and may be normal</div>
in your industry, I don't think that they're normal in the programming world<br>
in general.</blockquote><div> </div><div>I've never met a C++ programmer (other than yourself apparently) that doesn't pass structs/classes by ref.</div><div>That's generally considered absurd. And if you want evidence, just look at the STL, Boost, or any other C++ library you care to pick.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Most programmers don't care one whit about registers. They want the compiler to be </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
effecient in what it does, but they don't usually worry about stuff like whether<br>
a particular variable will fit in a register or not.</blockquote><div><br></div><div>That's true, and for that very reason, they were taught to ALWAYS use const T& whenever passing any non-trivial type. I've never met a single programmer who is an exception.</div>
<div>Universities teach this practise, books teach this practice, and every major C++ library you can point at implements this practise.</div><div><br></div><div>This has nothing to do with my particular use case. I've never seen an example of, or anyone advocating passing non-trivial data by value in C++.</div>
<div>One of my biggest criticisms of C++ is that people over-use ref's even in the (rare) cases where they shouldn't (passing a single int/float by const ref; relates back to my performance considerations), but that's certainly far better/safer than passing everything by value all the time when used in weak C++ templates (D could easily mitigate this problem).</div>
<div><br></div><div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span style>If they were, languages like Java and C# would never have gotten</span><br style><span style>anywhere in the first place. So, while D should definitely support what you're</span><br style><span style>trying to do, it's not what the average programmer is trying to do. Most</span><br style>
<span style>programmers don't care one whit about registers.</span><span style>They want the compiler to be</span> </blockquote><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span style>effecient in what it does, but they don't usually worry about stuff like whether</span></blockquote><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span style>a particular variable will fit in a register or not.</span></blockquote><div><br></div><div>They may not care, but the compiler does, and the compiler can't possibly be efficient if it's being told to copy heaps of data around all over the place.</div>
<div>There's nothing the compiler can do to magically make it go away, that's why it's so important.</div><div><br></div></div><div>Java and C# only support my argument, they pass everything by ref all the time, with the exception of C# structs, which behave exactly like in D. As a result, they introduced 'ref' too, except it works as expected in all use cases I presented above.</div>
<div>C# is the closest/best comparison here. C# is basically identical to D, but with one exception, 'ref' works in all situations you expect.</div></div>