From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_05,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,335027991b3a97ec X-Google-Attributes: gid103376,public From: dweller@dfw.net (David Weller) Subject: Re: Debug code Date: 1996/03/15 Message-ID: <4iborm$a27@dfw.dfw.net>#1/1 X-Deja-AN: 143778577 references: <1996Mar14.223326.13730@nosc.mil> organization: DFWNet -- Public Internet Access newsgroups: comp.lang.ada Date: 1996-03-15T00:00:00+00:00 List-Id: In article <1996Mar14.223326.13730@nosc.mil>, Kelly J. Grant 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