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

Walter Bright newshound2 at digitalmars.com
Tue Mar 16 08:27:27 UTC 2021


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 :-/


More information about the Digitalmars-d mailing list