DIP23 draft: Fixing properties redux

Steven Schveighoffer schveiguy at yahoo.com
Sun Feb 3 20:54:22 PST 2013


On Sun, 03 Feb 2013 22:06:27 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 2/3/13 9:23 PM, kenji hara wrote:
>> 2013/2/4 Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org
>> <mailto:SeeWebsiteForEmail at erdani.org>>
>>
>>     On 2/3/13 3:16 AM, Andrei Alexandrescu wrote:
>>     [snip]
>>
>>     Some more thinking got me to three simple principles that guide the
>>     proposed property design:
>>
>>     http://wiki.dlang.org/DIP23#__In_a_nutshell
>>     <http://wiki.dlang.org/DIP23#In_a_nutshell>
>>
>>
>>  > 2. A @property may have EXACTLY ONE or EXACTLY TWO parameters,
>> counting the implicit this parameter if at all. The ONE-parameter
>> version is ALWAYS a getter, and the TWO-parameter version is ALWAYS a
>> setter. There's no variadics, defaulted parameters, and such.
>>
>> Unfortunately, I can present a counterexample.
>>
>> struct S {
>>      static int value;
>>      static @property int foo() { return value; }
>>      static @property void foo(int n) { value = n; }
>>
>> }
>> void main() {
>>      int n = S.foo;
>>      S.foo = 1;
>> }
>>
>> Should they be disallowed, as like module level properties?
>
> Yes. No static properties.

Hm... can't see the reason why.  Static properties play no part in UFCS  
(which is what makes global properties confusing).  I hope it's not  
because you like your new nutshell rules too much...

Then again, @properties are for syntax, easy enough to make functions  
instead.

-Steve


More information about the Digitalmars-d mailing list