Reddit: why aren't people using D?

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Tue Jul 28 09:02:33 PDT 2009


Rainer Deyke 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.

May I remind the group of a possible solution I've offered before?

Here it is, slightly modified to go along with the current "no grouping of
setters and getters" trend.

--------------------------------------------------
class C {
    int foo.get() { ... }
    void foo.set(int value) { ... }
}

C c;
c.foo = 5; // c.foo.set(5);
i = c.foo; // i = c.foo.get();
d = &c.foo.get; // d = delegate to foo getter
--------------------------------------------------

It doesn't make your eyes bleed (I think). And you have a way to distinguish
between getter, setter and property.

The downside for D is that get() and set() may overshadow member functions
of the property type.

In my own language, this is not an issue, since get() and set() are special
functions that have the same meaning for each type. And overriding them is
just what a property is supposed to do.

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list