[Techtalk] Theory vs. practice

Malcolm rannirl-lc at otherkin.net
Wed Jan 16 14:10:24 EST 2002


On Wednesday 16 January 2002 12:59 am, Julie wrote:

> The problem is that coders very seldom consider all of the
> various assumptions they are making.  For example "No one is
> going to type a 1K string!".  Okay, if that's what you're
> assuming, test for it.

I don't know if anyone else does something similar, but one of
my standard practices is to have pre and post conditions explicitly
defined in my code (using macros in C, or conditionally defined inlines
in C++, which are the main languages I use besides perl).

I'm used to coding in environments where error checking is a performance
issue and frequently can't be afforded to the degree that would be "safe".
So the preconditions compile out of release builds but are there in debug
builds.

So I end up with something like (C version):

#ifdef DEBUG
 #define PRECONDITION(X)  if (X) fprintf(stderr, "Precondition #X failed at 
__LINE__ in __FILE__\n");
#ENDIF

It might not be the best way of doing it (anyone got better ways?), but it
makes things clear and easy to maintain (to me anyway) without the performance
overhead.



-- 
"And what are you?" "Alive. Everything else is negotiable."
- Sheridan and Franklin, Babylon 5

<<------------------------------------------------------------------>>
<<  This email is monitored by the US government under the auspice  >>
<< of the USA act. For private communication, ask me for my PGP key >>



More information about the Techtalk mailing list