<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 1 April 2014 15:53, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com" target="_blank">newshound2@digitalmars.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="">On 3/31/2014 10:02 PM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It's a really common pattern, it's obviously very useful, but it's surprising to<br>
me that people think that it's like, 'cool'.<br>
I get why it's done, and it's cool that D can do this (I use it a lot in my<br>
code), but I don't feel it's particularly elegant.<br>
</blockquote>
<br></div>
'alias this' is inelegant (sorry Andrei) but it was designed for precisely this purpose - being able to use a struct to wrap any other type, and forward to and override behaviors of that type. Nobody has found a better way.<br>
</blockquote><div><br></div><div>I don't think this is the only instance where alias this is useful though. It's one of those features that's unintuitive at first, but I find it pops up surprisingly often.</div>
<div>This is a super common pattern however, and my point was, that language already has a well defined reference type that is convenient and familiar, but it comes with some baggage that's not always desired.</div><div>
<br></div><div>It's kind of irrelevant though; the leading point was that one advantage might be that carrying the vtable beside the instance pointer would eliminate the hidden fiends in the class instance, but there's the classinfo pointer too.</div>
<div>Incidentally, why did you go with a dedicated classinfo pointer rather than use the 1st slot of the vtable like c++?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Fortunately, the inelegance can be encapsulated within that type, and the user of the type need not be even aware of it.<br></blockquote><div><br></div><div>Sure, but my point was that it seems to be _really_ frequently occurring. It's relatively unprecedented in D to be happy with such a commitment to boilerplate like that.</div>
<div>I can imagine there's a strong temptation to just reach for a class even though it's not appropriate in all situations. It's a lot less cognitive load; inexperienced programmers won't have trouble with the boilerplate implementation, or what to do when they hit edge cases.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Remember my halffloat implementation? It relied on 'alias this' to work. Just try doing that in C++ <g>.<br>
</blockquote></div><br></div><div class="gmail_extra">Of course, I use alias this all the time too for various stuff. I said before, it's a useful tool and it's great D <i>can</i> do this stuff, but I'm talking about this particular super common use case where it's used to hack together nothing more than a class without a vtable, ie, a basic ref type. I'd say that's worth serious consideration as a 1st-class concept?</div>
</div>