@property needed or not needed?

Jacob Carlborg doob at me.com
Mon Jan 28 04:31:34 PST 2013


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.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list