Future of memory management in D
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Fri Nov 19 16:14:41 UTC 2021
On Friday, 19 November 2021 at 15:39:54 UTC, 12345swordy wrote:
>
> It violate encapsulation. Which at that point you might as well
> make the l-value public.
>
> -Alex
It doesn't. Just like any other setter in any other language, it
does not constraint you to return a private field in the object
itself. You can return any value from any source, be it in object
itself, a sub-object, on heap or on stack. The only constraint is
to have it stored somewhere, so you can return a reference.
The main problem here, is that people expect for a value type to
behave like a reference type here, which isn't the case in any
other language too. Just try for example to return an int from a
getter in java, and do ++ on it. You'll get the same behavior as
in D.
Best regards,
Alexandru.
More information about the Digitalmars-d
mailing list