comp.lang.ada
 help / color / mirror / Atom feed
From: dweller@dfw.net (David Weller)
Subject: Re: Debug code
Date: 1996/03/15
Date: 1996-03-15T00:00:00+00:00	[thread overview]
Message-ID: <4iborm$a27@dfw.dfw.net> (raw)
In-Reply-To: 1996Mar14.223326.13730@nosc.mil

In article <1996Mar14.223326.13730@nosc.mil>,
Kelly J. Grant <grantk@manta.nosc.mil> wrote:
>> Jerry Blasdel (jblasdel@csc.com) wrote:
>> : I am tasked to add in debugging/diagnostic code
>> : into an existing ada application.  I would like
>> : to do somthing similar to a #ifdef DEBUG ... #endif
>> : like I would do in C but I did not think that Ada
>> : would let  me do anything like that.
>
>> : debug/diagnostic code that can remain in the
>> : source code.
>
>> comment out all lines with something like
>> --(DEBUG)  put_line("got to case #2");
>> we then run a nawk utility on the source code to enable debug messages
>> which effectively moves the cooment to the end of the line like:
>> put_line("got to case #2");  --(DEBUG)
>> there is of course another script to put it back at the beginning. It
>> is not as nice as defines but it works. Let me know if you find a better
>> way.
>
>
>That method is not bad, but there is a problem.  As soon as you recompile
>the source to include the new printouts, the problem may move or go away
>entirely (often while using addresses such as when using Windows or 
>other interfaces built using that *other* language :-)
>

The Ada 95 Booch Components takes a slightly different approach via
assertions.  While this lacks the expressiveness of "if DEBUG..."
sections of code, it certainly is helpful.

In certain "core" parts of the components, you'll find:
	pragma Assert ( This_Condition, "This condition not met");
(not verbatim, that was a simple example)

The result of that code, when assertions are turned on at compile
time, would be like an inlined "if" statement:

	if not This_Condition then
	   raise Assertion_Error; -- (with "This condition not met"
				  --  as the exception_string)
	end if;

While this introduces an element of non-portability, it has several
benefits:

1) It is a pragma, so compilers that don't support it will ignore it

2) It can be switched on during compilation, meaning you don't have to
touch the code

3) It minimizes the amount of "debug intrusion" in the actual code

Of course, the drawback is that if another vendor supports "pragma
Assert" in a different way, there might be an error :-)

All in all, I've found this feature to be enormously powerful.  I only
regret that it couldn't make it into the standard (yet :-)

-- 
		    GNAT = GNAT is Not an Ada Translator
==Ada 95 Booch Components: www.ocsystems.com/booch or www.dfw.net/~dweller==
Reality: Work, Work, Work, Guitar.         | Plugged: Fender Telecaster Deluxe
Fantasy: Guitar, Guitar, Guitar, Work(ha!) | Unplugged: Yamaha CG-150SA




       reply	other threads:[~1996-03-15  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1996Mar14.223326.13730@nosc.mil>
1996-03-15  0:00 ` David Weller [this message]
1996-03-18  0:00   ` Debug code Robert Dewar
1996-03-18  0:00     ` Robert A Duff
     [not found]       ` <dewar.827166947@schonberg>
1996-03-19  0:00         ` Norman H. Cohen
1996-03-15  0:00 ` Bob Kitzberger
1996-03-25  0:00 Debug Code Sundog Software
1996-03-25  0:00 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1996-02-27  0:00 Jerry Blasdel
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox