DIP23 draft: Fixing properties redux
Andrej Mitrovic
andrej.mitrovich at gmail.com
Tue Feb 5 17:40:28 PST 2013
On 2/6/13, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> That's why some of us have suggested
> making it so that you can mark variables with @property.
What Jonathan means is this:
struct S
{
int var; // modifiable, can take address
}
Now suppose later you want to turn var into a property:
struct S
{
@property int var();
@property void var(int);
}
This potentially breaks code if the user-code was using a pointer to
the public var field in the previous version of your library.
So instead we should have the ability to annotate fields with @property:
struct S
{
@property int var; // modifiable, can *not* take address
}
There's no run-time cost, but it disallows taking the address of var,
and it allows you to introduce property functions in the future
without breaking user-code.
More information about the Digitalmars-d
mailing list