comp.lang.ada
 help / color / mirror / Atom feed
From: bcf@swlpts1.ssd.ray.com (Felaco)
Subject: Re: Uninitialized variables, Java example
Date: 1996/07/24
Date: 1996-07-24T00:00:00+00:00	[thread overview]
Message-ID: <Dv28sG.ADq@ssd.ray.com> (raw)
In-Reply-To: 31EEACDA.64880EEB@sage.inel.gov


In article <Dv1sME.1u4.0.-s@inmet.camb.inmet.com>,
	arra@inmet.com (Arra Avakian) writes:

>This message appears even though all dynamic paths to the use of foo do in 
>fact initialize the variable. For example, a switch statement without a 
>default initializes the variable in all branches, but the compiler knows that 
>if the default case occurs, the variable is not initialized. The programmer 
>"knows" that the default case can not occur, but the compiler forces the 
>programmer to initialize foo to get a successful compile, i.e. it will not 
>produce the class file without the "unnecessary" initialization.

I recently did some work with a code checker on a large C program.  The 
customer had analyzed the system and had concerns about the quality 
based on the large number of errors the code checker reported.  Many 
of the errors were uninitialized variables.  The example you gave was a 
common reason for the errors.  It was a major hassle to track down the 
real programming errors from the errors that were really just 
lazy programming.  In a language like C, the least you can 
do is put a comment saying /* this case will never happen, so I didn't
bother programming for it */

>Some may view this as extreme, since the compiler can not know statically the 
>"truth", and forces a statically knowable work-around on the programmer. Is 
>this what some people want for Ada 0x? It seems to me to be a tradeoff between 
>efficiency (an unnecessary initialization to satisfy the compiler) and safety 
>(the compiler is then allowed to detect statically known cases of 
>uninitialized variables, i.e. true programming errors.) The programmer must 
>analyze the error message and determine whether it is a programming error to 
>be fixed, or a case where an "unnecessary" initialization is needed to quiet 
>the compiler.

In Ada, the example you gave does not apply, since all values of a case
statement must be covered anyway.  I think an Ada compiler is in a better 
position to check that all variables are initialized than a C compiler 
(or a C derivative language such as Java).

From my experiences, I would rather have to satisfy a pedantic compiler 
than a pedantic customer armed with a code checking tool.  ;-)  I don't 
believe performance is seriously degraded by unnecessarily initializing 
variables.  To allow even the possibility of an uninitialized variable 
being used is bad programming.  

>Arra Avakian
>Intermetrics, Inc.
>733 Concord Avenue
>Cambridge, Massachusetts 02138
>USA
>(617) 661-1840
>arra@inmet.com

-- 
-------------------------------------------------------------------------------
Chris Felaco                               Phone: x4631 (Raynet 444, Local 842)
Raytheon Company                                         Email: bcf@ssd.ray.com
-------------------------------------------------------------------------------





      parent reply	other threads:[~1996-07-24  0:00 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-18  0:00 Uninitialized "out" parameters Paul Whittington
1996-07-18  0:00 ` Adam Beneschan
1996-07-18  0:00   ` Robert Dewar
1996-07-19  0:00   ` Samuel Tardieu
1996-07-19  0:00     ` John Herro
1996-07-19  0:00       ` Tucker Taft
1996-07-23  0:00         ` Peter Hermann
1996-07-23  0:00           ` Robert A Duff
1996-07-19  0:00   ` Dale Stanbrough
1996-07-19  0:00     ` Adam Beneschan
1996-07-19  0:00     ` James A. Squire
1996-07-19  0:00       ` Adam Beneschan
1996-07-20  0:00       ` Michael Feldman
1996-07-21  0:00         ` Fergus Henderson
1996-07-21  0:00           ` Michael Feldman
1996-07-21  0:00             ` Robert Dewar
1996-07-22  0:00             ` Fergus Henderson
1996-07-23  0:00               ` Michael Feldman
1996-07-23  0:00                 ` Robert Dewar
1996-07-25  0:00                   ` Fergus Henderson
1996-07-24  0:00                 ` Fergus Henderson
1996-07-24  0:00                 ` Robert A Duff
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-19  0:00   ` Pascal Obry
1996-07-19  0:00     ` Peter Hermann
1996-07-18  0:00 ` Robert Dewar
1996-07-19  0:00   ` Peter Amey
1996-07-20  0:00   ` Fergus Henderson
1996-07-20  0:00     ` Robert Dewar
1996-07-21  0:00       ` Fergus Henderson
1996-07-21  0:00         ` Robert Dewar
1996-07-23  0:00           ` Fergus Henderson
1996-07-23  0:00             ` Robert A Duff
1996-07-24  0:00               ` Fergus Henderson
1996-07-24  0:00               ` Fergus Henderson
1996-07-23  0:00           ` Richard A. O'Keefe
1996-07-23  0:00             ` Robert Dewar
1996-07-24  0:00               ` Fergus Henderson
1996-07-24  0:00               ` Robert A Duff
1996-07-24  0:00               ` Fergus Henderson
1996-07-25  0:00               ` Richard A. O'Keefe
1996-07-25  0:00                 ` Robert A Duff
1996-07-23  0:00             ` Robert A Duff
1996-07-24  0:00               ` Richard A. O'Keefe
1996-07-24  0:00                 ` Robert A Duff
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-25  0:00                     ` Robert A Duff
1996-07-24  0:00                 ` Theodore E. Dennison
1996-07-25  0:00                 ` Frank Manning
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-26  0:00                     ` Frank Manning
1996-07-19  0:00 ` Michel Gauthier
1996-07-21  0:00   ` Robert A Duff
1996-07-19  0:00 ` Peter Amey
1996-07-21  0:00 ` Robert A Duff
1996-07-22  0:00 ` Is 'out' different from 'in out' (Was: Uninitialized "out" parameters) Michel Gauthier
1996-07-22  0:00   ` Tucker Taft
1996-07-22  0:00   ` Robert A Duff
1996-07-22  0:00     ` Robert Dewar
1996-07-23  0:00 ` Uninitialized "out" parameters John Herro
1996-07-23  0:00   ` Robert Dewar
1996-07-24  0:00     ` Peter Hermann
1996-07-23  0:00   ` Robert A Duff
1996-07-24  0:00     ` Uninitialized variables, Java example Arra Avakian
1996-07-25  0:00       ` Richard A. O'Keefe
1996-07-25  0:00         ` Robert A Duff
1996-07-25  0:00       ` Robert A Duff
1996-07-26  0:00   ` Uninitialized "out" parameters Stephen J Bevan
1996-07-26  0:00     ` Robert A Duff
1996-07-23  0:00 ` Is 'out' different from 'in out' (Was: Uninitialized "out" parameters) Michel Gauthier
1996-07-23  0:00   ` Robert Dewar
1996-07-24  0:00   ` Pascal Obry
1996-07-25  0:00   ` Tucker Taft
1996-07-24  0:00 ` Felaco [this message]
replies disabled

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