property syntax strawman
OF
no at spam.plz
Sun Aug 2 02:47:27 PDT 2009
Michiel Helvensteijn Wrote:
> Walter Bright wrote:
>
> > bool empty { ... }
> > void empty=(bool b) { ... }
> >
> > The only problem is when a declaration but not definition is desired:
> >
> > bool empty;
> >
> > but oops! That defines a field. So we came up with essentially a hack:
> >
> > bool empty{}
> >
> > i.e. the {} means the getter is declared, but defined elsewhere.
> >
> > What do you think?
>
> It is quite hack-ish. There are ways to have your cake and eat it too. I
> wouldn't settle for 'bool empty{}'.
>
> --------------------------------------------------
> bool empty {
> void set(auto value) { ... }
> auto get() { ... }
> }
>
> empty = false; // empty.set(false)
> auto b = empty; // auto b = empty.get()
> --------------------------------------------------
>
> for example, requires no hacks and no keywords. And has the added advantage
> that you can still use the getter and setter methods directly. To call them
> or get delegates from them.
>
> --
> Michiel Helvensteijn
>
I think I like this version better than using 'bool var{}' (the var= looks ok IMO, though).
Apparently very similar to the C# approach too (which is shorter, but uses an implicit variable):
public int humanAge
{
get
{
return age;
}
set
{
age = value;
}
}
More information about the Digitalmars-d
mailing list