comp.lang.ada
 help / color / mirror / Atom feed
From: mjp@itd.dsto.gov.au
Subject: Re: [Q] To initialise or not.
Date: 1996/04/30
Date: 1996-04-30T00:00:00+00:00	[thread overview]
Message-ID: <4m3se4$uda@fang.dsto.defence.gov.au> (raw)
In-Reply-To: 75602294@dorunth.hb.north.de


"Thorsten Behrens" <thorsten.behrens@dorunth.hb.north.de> writes:

>I tend to give all my declarations some initial value (if possible) _and_
>an initial comment (giving a shorter or longer text about its usage and
>the background of this variable). In my eyes this saves me from having
>non-initialized variables (causing errors which are sometimes nasty to
>find) and it saves people reviewing my sources from wasting too much time
>to guess what I was thinking when "inventing" a variable (normally, I would
>not use a variable called 'X', but instead would have called it
>'Some_Meaningful_Name').

I think what to do depends on the strenght of your compiler.

Ideally, the hardware would have store both a value, and a
bit indicating whether the value was valid (initialised) or
not. If this hardware support is not provided, hopefully,
your compiler will do a dataflow analysis and flag "used but
not set" variables, even this can fail in things like loops or
assignments in conditionals.

I always prefer to force a detectable error so for instance I
would tend to initialise to an absurd value. E.g. for a
divisor variable, I would initialise to 0 in the declarations,
that way if it is used before set it will cause a divide by
zero exception. Of course not all operations will cause such
obvious errors and in other cases I would tend to use such an
out of bounds value that you would at least see the error in
the output and go looking for it.

The really insidious errors are the ones that don't look like
a problem, i.e. appear plausable.

Michael

--
On Australia is prohibited from redistributing this document in any way
Dr Michael Pilling                         Phone: +61 8 259 7017
DSTO ITD/SE 171 Labs                       Fax: +61 8 259 5589
PO Box 1500, Salisbury SA 5108, Australia  Michael.Pilling@dsto.defence.gov.au




  parent reply	other threads:[~1996-04-30  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-25  0:00 [Q] To initialise or not JP Thornley
1996-04-26  0:00 ` Ken Garlington
1996-04-26  0:00   ` Robert A Duff
1996-04-27  0:00   ` Robert Dewar
1996-04-27  0:00     ` Robert A Duff
1996-04-26  0:00 ` Robert I. Eachus
1996-04-26  0:00 ` Ken Garlington
1996-04-26  0:00 ` Theodore E. Dennison
1996-04-26  0:00   ` Robert A Duff
1996-04-27  0:00     ` Thorsten Behrens
1996-04-28  0:00       ` Robert Dewar
1996-04-30  0:00       ` mjp [this message]
1996-05-02  0:00       ` Bob Gilbert
1996-04-27  0:00 ` Robert Dewar
replies disabled

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