version(CONTRACTS) for contracts?
Daniel Keep
daniel.keep.lists at gmail.com
Wed Nov 8 19:30:23 PST 2006
Bill Baxter wrote:
> BCS wrote:
>> I think what you are trying for is what class invariants do.
>>
>> http://www.digitalmars.com/d/class.html#invariants
>>
>> == Quote from Bill Baxter (dnewsgroup at billbaxter.com)'s article
>>> Is there a version statement that corresponds to whether or not
>>> contracts are enabled or not?
>>> I'd like to do something like
>>> in { _check_data_structure_integrity() }
>>> for a bunch of my methods in my class, then something like
>>> version(Contracts) {
>>> _check_data_structure_integrity() {
>>> // do a bunch of complicated stuff here
>>> // and assert if anything's messed up.
>>> }
>>> }
>>> --bb
>>
>
> Class invariants. Indeed so!
>
> Still I don't think that covers all use cases. If my invariant is very
> slow to compute and I have some methods that are very frequently called,
> then I'm not going to want to check it for every single method call. It
> could make debugging way too slow. Plus, if I know these three methods
> are the only three that affect this invariant then only those three
> methods should trigger an invariant check.
>
> So I think something more fine grained than class invariants is needed.
> Something like version(_DContracts) would do it.
>
> --bb
Why don't you do something like this?
> in { version(SlowInvariants) _check_stuff(); }
>
> // ...
>
> version(SlowInvariants) {
> void _check_stuff() {
> // ...
> }
> }
Then, when compiling, stick a -version=SlowInvariants on the command
line. You should be able to set up a release and debug target in bud so
you only need to do this once.
-- Daniel
--
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d
mailing list