DIP23 draft: Fixing properties redux
Jonathan M Davis
jmdavisProg at gmx.com
Mon Feb 4 14:52:06 PST 2013
On Monday, February 04, 2013 17:28:24 Andrei Alexandrescu wrote:
> On 2/4/13 2:04 PM, Jonathan M Davis wrote:
> > We could save a lot of boilerplate code if we can simply make it variables
> > and property functions guaranteed to be swappable without breaking code.
> I think this is quite powerful. The way we can do this is by making
> properties emulate a subset of actual variables.
Yes. There are things that propery functions need to emulate from normal
variables (hence the rewrites with ++ and += and whatnot), and there are of
course things that they can't emulate (like taking the address of a variable).
But what we also need is a way to mark a variable as a property and then make
it so such a variable and property functions have the same capabilities so
that you're guaranteed to be able to swap between the two without breaking
code. As soon as one of the two has capabilities that the other doesn't have,
or there's a major semantic change between them (like taking the address works
on one but not the other or the type returned by taking the address differs),
then you can't do that.
Which is why I would argue that we need to be able to mark variables with
@property (which either makes it so that you can't do anything with them that
you can't do with a property function or makes it so that it lowers to
property functions for getting and setting), and we need to disallow taking
the address of property functions as well as anything else that you could do
with a variable that we can't emulate with a property function.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list