D community's view on syntactic sugar
Seb
seb at wilzba.ch
Mon Jun 18 20:12:04 UTC 2018
On Monday, 18 June 2018 at 01:06:48 UTC, evilrat wrote:
> On Sunday, 17 June 2018 at 17:48:21 UTC, FromAnotherPlanet
> wrote:
>> On Sunday, 17 June 2018 at 16:52:59 UTC, Neia Neutuladh wrote:
>>> The only case where D loses out is compared to { get; private
>>> set; }.
>>>
>>
>> That's a pretty big thing to give up. That allows for pretty
>> valuable control over visibility of encapsulated properties.
>
> He means that in D this is split like that, which isn't as
> clean as C# does
>
> class MyClass
> {
> private int _myProp; // backing field
> private @property void myProp(int a) { _myProp = a; } //
> private setter
> public @property int myProp() { return _myProp; } // getter
> }
Well the cool part about D is that we can generate such sugar
without necessarily needing to have it in the language (though a
better property syntax would be great).
Anyhow here's an example from the accessors package
(https://github.com/funkwerk/accessors):
import accessors;
class WithAccessors
{
@Read @Write
private int num_;
// list all your fields here
mixin(GenerateFieldAccessors);
}
More information about the Digitalmars-d
mailing list