Invariants for methods

Jens Mueller jens.k.mueller at gmx.de
Thu Nov 18 12:42:49 PST 2010


Andrei Alexandrescu wrote:
> On 11/18/10 12:08 PM, Jens Mueller wrote:
> >What I'd even like better (because contracts are release specific):
> >release {
> >     const currentWidth = width;
> >     const currentHeight = height;
> >     scope (exit) {
> >         assert(currentWidth == width);
> >         assert(currentHeight == height);
> >     }
> >}
> >But that does not work. Why do we have special syntax for debug but not for
> >release. Both seem to me very similar. In the end I tend to think
> >release/debug as a shorthand for version(release/debug). But that's not
> >quite right. Somehow it's allowed to write version(unittest) {}
> >equivalently for unittest {}. But for debug/release there is no such
> >thing. Why this asymmetry?
> >
> >Jens
> 
> I think it's just for pragmatic reasons (avoid allocating a keyword
> for something you can do a different way). Also, it's more often
> that you want to insert extra code in debug builds. It's odd that
> you don't want the checks in debug mode, for example.

Sorry. I shouldn't have said release {}. That was wrong.
Basically I want the check to behave the same as a normal contract does.
So actually I want
non-release { // goes only away in release mode
    ...
}
I mean if I compile with -release all contracts should go away. With
debug { } I'm now mixing things. Because my contract will only be
checked if compiled with -debug.

Jens


More information about the Digitalmars-d mailing list