Reddit: why aren't people using D?

KennyTM~ kennytm at gmail.com
Tue Jul 28 10:35:10 PDT 2009


Rainer Deyke wrote:
> Benji Smith wrote:
>> For my money, the best solution is a simple "property" keyword as a
>> function modifier. Only functions with the "property" modifier would be
>> allowed to pose as fields (getters called without parens, setters called
>> using assignment syntax). But, in all other respects, they should act
>> just like functions.
> 
> I like being able to distinguish between the property itself and its
> setter/getter function.
> 
> For example, let's say 'y' is a property of 'x'.
> 
> z = x.y; // Calls the getter.
> x.y = z; // Calls the setter.
> z = &x.y; // But what's this?  The setter, the getter, or the property
> itself?
> 

class X {
   int _y;
   property pure const int y() { return _y; }
   property void y(int y_) { _y = y_; }
   pure const int y(int i, int j) { return _y+i*j; }
};

auto x = new X;
int delegate() z_getter = &x.y;
void delegate(int) z_setter = &x.y;
int delegate(int,int) z_irrelevant = &x.y;
int* z_variable = &x._y;
// What do you mean by "the property itself"? there's no single address 
to such thing.

z_setter(16);
assert(z_getter() == 16);
assert(z_irrelevant(3,4) == 28);
assert(*z_variable == 16);


> That's why I support opSet_foo and opGet_foo (although I'd prefer the
> simpler get_foo and set_foo).
> 
> 



More information about the Digitalmars-d mailing list