Is `alias this` a mistake?

IGotD- nise at nise.com
Sat Aug 7 11:11:32 UTC 2021


On Saturday, 7 August 2021 at 06:05:02 UTC, Ola Fosheim Grøstad 
wrote:
>
> Functional programming requires you to conceptually pass by 
> value, then passing it by reference becomes an optimization. 
> But in D this is lost since you also can pass by reference. So 
> there is no advantage to having the struct/class split.

It's an interesting aspect of language design which seems to 
proliferate almost all imperative languages despite the main use 
is not functional programming. Rather having the compiler 
optimizing the parameter passing (which some do underneath 
anyway), default is copy and it has been like that for decades. 
Not sure what the historical impact is, maybe that early CPUs had 
few registers and the stack was the only choice.

In the case of functional programming, I would just let the 
programmer manually copy the struct inside the function body as 
no assumption can be made if the struct is passed as reference 
(pointer) or in registers, or just have a keyword that forces the 
struct to be copied on stack.


More information about the Digitalmars-d mailing list