@property needed or not needed?
Maxim Fomin
maxim at maxim-fomin.ru
Mon Jan 28 06:00:15 PST 2013
On Monday, 28 January 2013 at 12:31:35 UTC, Jacob Carlborg wrote:
> On 2013-01-28 12:44, Robert wrote:
>> @property use:
>>
>> I'd like to point out, that regardless of the "with
>> parens/without
>> parens" stuff, marking properties with @property makes sense.
>> So that
>> tools and frameworks can recognize them as such.
>
> I completely agree. I have created a struct called "attribute"
> only to be used as an attribute for other types that should
> only be attributes:
>
> struct attribute {}
>
> @attribute struct foo {}
>
> Even though @attribute in this case doesn't to anything it
> shows the intent clearly. Same thing why I like explicit
> interfaces and abstract classes compared with C++.
>
>> This also implies that
>> fields that are meant as properties should be declared
>> @property and the
>> compiler should generate getter/setter so it behaves exactly
>> like a
>> manually created property. May I add this to DIP21?
>>
>> Having the compiler lower the following:
>>
>> @property int a;
>>
>> to
>>
>> private int __a;
>>
>> @property int a() {
>> return __a;
>> }
>> @property int a(int new_a) {
>> __a=new_a;
>> return __a;
>> }
>
> I would love that. But the setter should return void and the
> compiler should to property rewrites.
Returning void instead of int in the example break assignment
chaining a = b = c. Besides, how such implicitly defined
functions may call user defined code (check input validity, call
events, etc.)?
More information about the Digitalmars-d
mailing list