Yet a new properties proposal
Dimitar Kolev
DimitarRosenovKolev at hotmail.com
Wed Jul 29 12:06:25 PDT 2009
Bill Baxter Wrote:
> The point is to be able to start with
>
> class Foo
> {
> int a;
> }
>
> and later change implementation or add access monitoring without
> affecting all the code that already acceesses Foo's .a field.
> So this should compile both before and after changing Foo.a from a
> field to a property:
>
> Foo x;
> x.a = 3;
> x.a += 3; // **
> writefln("x.a now %s", x.a);
>
> --bb
> ** this doesn't currently work with D when a() is a function, but it should.
As long as there is a function called a inside that class there will be no way to call a.a without calling that function or calling that member value.
You just need a special word for that.
And what I am proposing is not a word but simple a character #.
You want to start with:
class a
{
int a;
}
but when I put
class a
{
int b;
int b() { return 3;}
}
there will be no way to distinguish between the two calls without the compiler being forced to call an error and yet again the user will have to change his/her code.
Just make all properties accessed by # and you will save yourself the ambiguities of calling a function or a property with the same names.
More information about the Digitalmars-d
mailing list