DIP4: Properties
Steven Schveighoffer
schveiguy at yahoo.com
Sun Jul 26 10:02:46 PDT 2009
On Sat, 25 Jul 2009 03:29:01 -0400, Nick Sabalausky <a at a.a> wrote:
> "Leandro Lucarella" <llucax at gmail.com> wrote in message
> news:20090724212800.GA2120 at homero.springfield.home...
>>
>> I think you have good points about not repeating yourself, but I still
>> find it too magical. I think I prefer something a little more explicit,
>> even if I have to repeat myself.
>
> I assume you're referring to the automatic "value" and "set" variables
> here,
> right? The proposal seems to be getting a lot of complaints about those.
> But, I haven't seen any explanations of actual problems with them beyond
> "it's magical", "I prefer", etc (unless I've overlooked something, and my
> apologies if I have). Any abstraction could be argued to be "magical".
>
I haven't read all the replies yet, but the one issue I have is similar to
the array's magical length property:
struct S
{
int value;
int prop
{
get()
{
return value; // ambiguous
}
}
}
If you used something that was not a variable name (like the fix for
arrays -- $) then you do not have a conflict.
But I like the idea that Leandro brought up best.
One other issue that his idea solves -- in an internal private method, you
might want to use the underlying storage directly instead of calling the
property for performance reasons, this would be difficult to address with
a context keyword.
-Steve
More information about the Digitalmars-d
mailing list