Future of memory management in D

Rumbu rumbu at rumbu.ro
Sat Nov 20 11:53:20 UTC 2021


On Saturday, 20 November 2021 at 10:08:55 UTC, Dom DiSc wrote:
> 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.

Please read the entire thread.

The original issue was the how can I design a property in D so I 
can write:

```
  area +=1;
```

The solution with ref return came from Atilla, not from me.




More information about the Digitalmars-d mailing list