Invariant for default construction

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 17 13:09:13 PST 2014


On 11/17/14 3:51 PM, Walter Bright wrote:
> On 11/17/2014 12:32 PM, Steven Schveighoffer wrote:
>> On 11/17/14 3:02 PM, Martin Nowak wrote:
>>> Walter is about to fix an old bug [1] so that invariants are now called
>>> before destruction and for non-default construction.
>>
>> This sounds good.
>>
>>> A remaining question is whether invariants should also be called for
>>> default construction [2].
>>
>> I'd say no. There are better ways to test for valid data in the .init
>> version of
>> the object/struct that don't involve a runtime check.
>
> Not only that, the runtime check would occur every time an object is
> created, yet the .init will always be the same. Doing this check would,
> I fear, cause people to disable invariants as not worth the expense.

It's already not worth the expense for Objects, which Object.invariant 
for every function call, even if you don't define one.

-Steve


More information about the Digitalmars-d mailing list