Discussion Thread: DIP 1040--Copying, Moving, and Forwarding--Community Review Round 1

12345swordy alexanderheistermann at gmail.com
Tue Mar 16 13:40:36 UTC 2021


On Tuesday, 16 March 2021 at 08:27:27 UTC, Walter Bright wrote:
> On 3/15/2021 10:18 AM, H. S. Teoh wrote:
>> I'm sure Walter would have made alias this illegal in classes 
>> a long
>> time ago, if it were possible without problems.  I'm 
>> suspecting the
>> "don't break existing code" bugbear is among the reasons.
>
> Right.
>
>> I used to be a big fan of alias this, esp. multiple alias 
>> this.  Now,
>> after some experience with maintaining code that use alias this
>> willy-nilly, I'm starting to agree with Walter's stance that 
>> alias this
>> in general was a bad idea.  Although there are definitely 
>> cases for
>> which it's actually useful, the problems it brings along make 
>> it of
>> questionable value as a general language feature.  I'd also be 
>> in favor
>> of getting rid of it, at least from classes, if not 
>> completely. (The
>> latter is probably impossible; quite a lot of my own code 
>> relies on it,
>> and I imagine I'm not the only one using it among the users of 
>> D.)
>
> Right, we're kinda stuck with it. But move constructors are a 
> new thing, and ignoring interaction with class alias thing will 
> not break existing code. If someone wants to use move 
> constructors, don't mix them with class alias this.
>
> Alias this should only be used with structs, and modestly at 
> that. Being clever with it will only annoy the dragon :-/

Here is my suggestion, deprecate alias this for classes, but the 
date for the removal of them to be never. With the ability to 
silence the deprecation if needed. There done. Simple. It won't 
break old code, but it will discourage new bad code from being 
created.

-Alex


More information about the Digitalmars-d mailing list