UDP enhancement

Jonathan M Davis jmdavisProg at gmx.com
Tue Jul 2 11:01:43 PDT 2013


On Tuesday, July 02, 2013 19:49:39 Kapps wrote:
> 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.

inout would probably be better then. But without that, anyone wanting to be 
const-correct is going to have to declare all of the getters themselves. inout 
isn't quite there, because there are many cases where you really do want to 
return const even when the object is mutable, but it would probably be a good 
compromise.

- Jonathan M Davis


More information about the Digitalmars-d mailing list