Getters/setters generator
Andrei Alexandrescu via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Tue Jan 17 07:59:26 PST 2017
On 1/17/17 12:08 PM, Mark wrote:
> On Tuesday, 17 January 2017 at 09:17:56 UTC, Andrei Alexandrescu wrote:
>> On 1/17/17 9:32 AM, Eugene Wissner wrote:
>>> Ah, well thanks. I don't think it makes much sense since it would be
>>> easier to write a complete setter if the user needs extra checks.
>>> Accessors are there only for the generation of the standard methods,
>>> that just get or set some object property.
>>
>> Hmmm... that's a bit of a bummer because it helps only the degenerate
>> case (accessors are there as placeholders for future extensions, and
>> otherwise offer no protection whatsoever compared to a public value).
>> The question would be then what would be use cases for the accessors.
>> Predicated setters are not just a random thing one might want out of
>> many possibilities, it's a frequent pattern. -- Andrei
>
> Given that D supports class invariants, is there a real need for
> predicated setters?
The invariant is evaluated after the setter has taken place, i.e. after
the object has been corrupted. The setter guard prevents corruption from
happening. -- Andrei
More information about the Digitalmars-d-announce
mailing list