UDP enhancement

Kapps opantm2+spam at gmail.com
Tue Jul 2 10:49:39 PDT 2013


On Monday, 1 July 2013 at 01:35:40 UTC, Jonathan M Davis wrote:
>
> I believe that the way that this sort of enhancement has 
> typically been
> suggested is to do something like
>
> public @property int value;
>
> which would be lowered to something like
>
> public @property int value() @safe const pure nothrow { return 
> _value; }
> public @property int value(int v) @safe pure nothrow { return 
> _value = v; }
> private int _value;
>
> - Jonathan M Davis

As someone who uses properties almost everywhere, and almost 
never uses public fields, this is one of my biggest gripes with D 
remaining. It's incredibly annoying to have to do things like

private int _width;
/// Gets or sets the total width, in pixels, of this control.
@property int width() const {
     return _width;
}
/// ditto
@property void width(int value) {
     this._width = value;
}


Something like

/// Gets or sets the total width, in pixels, of this control.
@property const int width;

Is just so much nicer and saves so much bloat. I feel like the 
current property syntax is one of those places where IDE code 
snippets will start to become, not necessary, but extremely 
useful. It's the type of manual repetition that D aims to avoid, 
but in this case fails at.
I don't know if I agree with automatically expanding to const 
though. I'd like to be able to do '@property Control parent' 
without needing to return a const(Control) because the property 
is expanded to be const. Although if we had a virtual keyword, 
final is something that I think should be default for properties, 
and I think it's a mistake that the current @property doesn't 
infer final in the first place. Safe and nothrow are two 
assumptions that are probably quite safe to assume for the most 
part as well.


More information about the Digitalmars-d mailing list