August 23, 2007
"Manfred Nowak" <svv1999@hotmail.com> wrote in message news:faki47$2ifr$1@digitalmars.com...
> Regan Heath wrote
>
>> "Properties are member functions that can be syntactically treated
>> as if they were fields"

What I think it means is simply that you can get/set a property with notation that looks as though you're getting/setting a field.

>> I was under the impression the main benefit to properties was
>> being able to replace an existing field (one in use by some user
>> code) with a property and have it work without user code changes.

I think that's more or less what was meant to happen, but it hasn't quite turned out that way.

> For me the definition implies that fields can replace properties, but
> no property can replace a field.

I don't see how you work that out.

> I read the definition above like this:
> : if a member function can be syntactically treated as a field, then
> : it is a property
> i.e.,  properties have less syntactical power than fields.
>
> Because member functions with at most one formal parameter can be
> treated as fields in assignments, i.e. without the parentheses, D has
> properties according to the definition in the docs.
>
> All those recognizable errors in yours and Stewart's examples are
> based on the wrong assumption, that properties are more powerful than
> fields.

I suppose properties have less syntactical power, but more power in terms of practical uses.  If that makes sense....

Stewart. 

August 23, 2007
On Thu, 23 Aug 2007 22:20:16 +0100, Stewart Gordon wrote:

> I suppose properties have less syntactical power, but more power in terms of practical uses.  If that makes sense....

Yes I can see what you mean.

( silly example: )
    long x() } return { _x * 2 + _y; }
    void x(int y) { _x = y / 2; _y = y - 2; }
    void x(char[] y) { . . . }

    foo.x = 16;
    long A = foo.x;
    foo.x = "abc";
    long B = foo.x;

On the other hand, when I first read about properties I thought
"Brilliant!" and started using them. However it soon became apparent that
they were not brilliant but were really a PITA. I can't be bothered with
them now as they just increase the cost of maintenance, because they cannot
be syntactically be treated as the fields that they look like. They deceive
coders because they look like fields but they are not fields.

In short, properties in D are evil in the same way that 'goto' is evil. If you use them, be prepared to pay extra for them.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
1 2
Next ›   Last »