Reddit: why aren't people using D?
Benji Smith
dlanguage at benjismith.net
Mon Jul 27 17:40:59 PDT 2009
Andrei Alexandrescu wrote:
> Rainer Deyke wrote:
>> Nick Sabalausky wrote:
>>> I can't be nice about this: Any programmer who has *any* aggrivation
>>> learning any even remotely sane property syntax is an idiot, period.
>>> They'd have to be incompetent to not be able to look at an example
>>> like this:
>>>
>>> // Fine, I'll throw DRY away:
>>> int _width;
>>> int width
>>> {
>>> get { return _width; }
>>> set(v) { _width = v; }
>>> }
>>>
>>> And immediately know exactly how the poroperty syntax works.
>>
>> I don't know exactly how this is supposed to work. The basic idea is
>> obvious, but:
>> - How does it interact with inheritance? Can I override properties?
>> Can I partially override properties (setter but not getter)?
>> - Can I write a setter that accepts another type?
>> - Can I write a templated setter that accepts *all* types? If so, how?
>> - Can I create a delegate from a setter/getter? If so, how?
>> - I assume that getters/setters can have individual access specifiers
>> (i.e. private/protected/public), but is that really the case?
>>
>> Dedicated property syntax isn't hard to learn, but it's not as obvious
>> as you make it our to be. Note that none of these issues exist with
>> opGet_foo, which follows the same rules as all functions.
>>
>
> +1
>
> Andrei
Also agree. The C# syntax is a little too complex for my taste, and it
makes some things ugly or impossible (like, what if I want a public
getter but a protected setter?)
I like the mechanics of the opGet_Xxx proposal, but aesthetically, it
just makes my eyes bleed (as do the other "op" functions, like opApply,
that don't technically overload any "op"erators).
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.
--benji
More information about the Digitalmars-d
mailing list