Omittable parens is an evil
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sat Jul 19 12:02:57 PDT 2008
"Mike" <vertex at gmx.at> wrote in message news:op.uejk9fs8kgfkbn at lucia...
> On Sat, 19 Jul 2008 15:32:36 +0200, Koroskin Denis <2korden+dmd at gmail.com>
> wrote:
>
>> Why not have special syntax for properties, like:
>
> This has come up multiple times - that's one of the few things where C#
> wins over D. If I may repeat a suggestion I made once, maybe Walter can be
> hypnotized into implementing it if I just repeat it often enough :)
>
> class foo
> {
> private int _bar;
> property int bar
> {
> opGet() { return _bar; }
> opSet(auto value) { _bar = value; }
> opAddAssign(auto value) { _bar += value; } // it's extremely
> extendable!
> }
I agree, but having to reimplement the opXxxAssign methods for every
property would quickly become tedious. A much simpler way to do it is to
define that:
obj.property op= expr;
is exactly the same as:
obj.property.opSet(obj.property.opGet() op expr);
I believe C# does this. Still it'd be nice to allow opXxxAssign for
properties to overload the default behavior, but it'd at least have a
reasonable fallback.
In the initial designs for MiniD, when it was still a statically-typed
language, I defined them exactly in this way, and then abstracted the idea
by having a 'namespace' construct which could be used to implement
properties, group symbols logically, and so on.
None of this will ever get into D.
More information about the Digitalmars-d
mailing list