Second Draft: Turn properties into first class accessors
Paul Backus
snarwin at gmail.com
Thu Feb 6 03:34:22 UTC 2025
On Thursday, 6 February 2025 at 00:52:55 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> There is a guarantee that I want for this.
>
> The compiler will guarantee that for every assignment that has
> a paired read, that there will be no other reads.
>
> ```d
> @property {
> int value();
> void value(int);
> }
> ```
>
> ```d
> value += 2 + value;
> ```
>
> Would be:
>
> ```d
> {
> int __generatedName = value;
> value(__generatedName + 2 + __generatedName);
> }
> ```
Descending into the RHS expression and rewriting occurences of
`value` there is complete insanity. Not only does it fall apart
the instant you try to nest an expression like this recursively:
value += (value += 2); // what now??
...it also has the potential to remove observable side effects
from a program, which is, of course, completely unacceptable.
At the end of the day, all of this @property stuff is just syntax
sugar for normal function calls. If you can't figure out how to
make escape analysis work with function calls, that's a problem
for your design. Leave @property out of it.
More information about the dip.development
mailing list