Future of memory management in D

Dom DiSc dominikus at scherkl.de
Sat Nov 20 10:08:55 UTC 2021


On Friday, 19 November 2021 at 16:31:19 UTC, rumbu wrote:
>
> ```d
> class Square
> {
>     private double width;
>     public double area()
>     {
>         return width * width;
>     }
>     public ref float area(double x)
>     {
>        width = sqrt(x);
>       //what should I return here as ref?
>     }
> }
> ```
Why should a setter return anything? (But of course it could, if 
you wish so).
This is not neccessary to realize the += operator.

I talked about the GETter that should not return a reference. 
Because the reason to have a getter (and no setter at all) is to 
make the value visible to the public, but not allow any hook to 
anything within my object. Beside the getter the object should 
remain a complete black box.
If any other behavior is desired, use something else than a 
getter property.
It's no problem to have ordinary members that return references 
and of which you can get the address or pointers or whatever. But 
properties should stay as close to the basic needs of a pure 
value as possible.
We don't need another way to write ordinary functions.


More information about the Digitalmars-d mailing list