Restrict Class Properties?

Michiel nomail at please.com
Thu Feb 22 10:44:47 PST 2007


Miles wrote:

> 1. Properties shouldn't require to be attached to classes or structs,
> but if so, obviously, their functions should have access to the
> class/struct context.

Could you explain this one? What would a property without an associated
struct/class be? A property of the whole program perhaps?

> 3. Properties are translated on basis on what operations would have been
> done on it if it were a variable, and not a fancy representation of a
> function call. This should allow  property++  and  property += 5  (given
> that it provides both a getter and at least a setter).

But ++, -- and op= have their own definitions with certain class-types
that can't be defined in terms of only setter and getter functions. You
wouldn't want those operators to be expanded to (= x + 1), (= x - 1), (=
x op y), since those are less efficient and perhaps subtly different
from their expanded counterparts.

If you truly want them to work on properties, they should be defined
next to the setter and getter functions for that property.

> 5. Ordinary functions should always require () to be executed. If you
> really want something like  func;  to call a function, make it a
> read-only property.

I don't agree. Properties shouldn't be used as functions at all. They
should manage writes and reads to a single property.

> 6. Ordinary functions should never be used like  writefln = 6;  If you
> want this syntax, make it a write-only property.

Agreed on this point. I hadn't even realized this was possible at the
moment.

-- 
Michiel



More information about the Digitalmars-d mailing list