Precondition vs debug{}

Bill Baxter dnewsgroup at billbaxter.com
Tue Oct 2 20:00:30 PDT 2007


Is there any difference between these two methods of implementing a 
precondition?:

-----------------------
void foo(int x)
in {
    // do some checking
}
body
{
    ...
}
-----------------------

and this:

-----------------------
void foo(int x)
{
   debug {
      // do some checking
   }
   ...
}
-----------------------

And if "some checking" is just an assert() or two is there any 
difference between the 'in' precondition version and just plain

-----------------------
void foo(int x)
{
   assert(something, "something's not right");
   ...
}
-----------------------


Just curious.  Typing 'in' and 'body' just doesn't come naturally to me. 
  But I've seen plenty of D code with an in{}body{} pair where the in{} 
only contains one assert(), so I was wondering if there was some 
advantage to the extra verbiage that I was missing out on.

--bb


More information about the Digitalmars-d-learn mailing list