comp.lang.ada
 help / color / mirror / Atom feed
From: ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe)
Subject: Re: Uninitialized "out" parameters
Date: 1996/07/23
Date: 1996-07-23T00:00:00+00:00	[thread overview]
Message-ID: <4t1s3n$chv@goanna.cs.rmit.edu.au> (raw)
In-Reply-To: dewar.837994885@schonberg


dewar@cs.nyu.edu (Robert Dewar) writes:
>Yes, but Ada is not dyunamically typed, it uses a decidable static type
>system, and there are VERY good reasons why comparable static systems
>cannot be designed for dealing with the uninitialized variable problem
>(please reread carefully my example of the 2 gig array in an allocate
>on demand environment -- and response to how your decidable system
>would accomodate this requirement).

In my experience of marking student C programs, trying to use uninitialised
variables is the commonest non-syntactic error.  I have found the program
'lclint' _extremely_ useful when marking because it does a very good job of
noticing possible uninitialised variables.  It even manages on occasion to
do a useful (not perfect) job with arrays.  On one student program it
reported 62 such warnings, and I thought it was crying wolf, but on closer
inspection every single warning (most of the involving arrays) was right.

I note that SPARCompiler Pascal, which I do not otherwise care for, has
a "-Rw" command line option for extending uninitialised variable tracking
into records (but not arrays).

Over the last year I have been coming to the conclusion that the ability to
use uninitialised variables is one of those programming language features
that I am better off without.  I mean, ever since "A Discipline of
Programming" I thought it was a good idea, but I also thought I was a hot
enough programmer not to need such a crutch.

Then I started using lclint, and it started finding mistakes that I hadn't
noticed.

True, Ada is so designed that sound and complete compile-time detection
of using uninitialised variables is impossible ('separate' probably
contributes something to this).  It's also worth noting that the change
to 'out' parameters in Ada 95 doesn't make it noticably harder for a
compiler that *tries* to do a *useful* amount of checking, as for example
gcc -O2 -Wall does.

But some day Ada will have a successor.  And I can see no reason why that
successor should not do a better job than Ada in this respect.

I mentioned lclint.  lclint does something rather interesting:  it tracks
the allocation state of pointers, via annotations.  In effect, it uses a
richer type language than C, in which it is possible to express things
like "this is a non-null pointer to an object having no other pointers";
just as Dijkstra's notation tracks "obligation to initialise" in the
type system, so lclint tracks "obligation to free" in the type system.

Fergus Henderson has posted in this thread.  He's involved in the
Mercury project, and Mercury, in addition to "types" uses something
called "modes" which in effect enrich the type system so that the
programmer can say
	"this procedure takes a record in which the x and y fields
	 are initialised and the z and w fields aren't, and
	 initialises the w field"
and the compiler can *prove* at compile time that no uninitialised
variable access is possible.

There has been other work done on including state and effects in type
systems, but lclint and Mercury are practical tools you can FTP today.

In the short term, the array problem can be handled the way Dijkstra's
notation does:  by having dynamic bounds, so that the initialised part
of an array is the part within the dynamic bounds, and the rest of the
array acts as if it didn't exist.  SPARCompiler Pascal has
	varying [n] of char
as its type for strings; this is the same idea as Dijkstra's arrays
except that the lower bound is frozen at 1.  Such a string may have
*room* for 100000 characters, but if it was last assigned a string of
5 characters, those 5 are the only ones you can access.

What does that mean for Ada?  It means that the use of abstract container
types like queues and APL/Fortran-90/Torrix-style "whole array" operations
are not just a clearer way to say what you mean, they are a good way to
avoid a class of errors.

-- 
Fifty years of programming language research, and we end up with C++ ???
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.




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

Thread overview: 104+ 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           ` Richard A. O'Keefe [this message]
1996-07-23  0:00             ` Robert Dewar
1996-07-24  0:00               ` Robert A Duff
1996-07-24  0:00               ` Fergus Henderson
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                 ` Theodore E. Dennison
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-25  0:00                 ` Frank Manning
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-26  0:00                     ` Frank Manning
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-19  0:00 ` Peter Amey
1996-07-19  0:00 ` Michel Gauthier
1996-07-21  0:00   ` Robert A Duff
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 A Duff
1996-07-24  0:00     ` Uninitialized variables, Java example Arra Avakian
1996-07-25  0:00       ` Robert A Duff
1996-07-25  0:00       ` Richard A. O'Keefe
1996-07-25  0:00         ` Robert A Duff
1996-07-23  0:00   ` Uninitialized "out" parameters Robert Dewar
1996-07-24  0:00     ` Peter Hermann
1996-07-26  0:00   ` 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 ` Uninitialized variables, Java example Felaco
  -- strict thread matches above, loose matches on Subject: below --
1996-07-29  0:00 Uninitialized out parameters W. Wesley Groleau (Wes)
2016-04-05 12:02 ahlan
2016-04-05 13:17 ` rieachus
2016-04-05 14:07   ` ahlan
2016-04-06  9:45     ` Mark Lorenzen
2016-04-06 21:01       ` Jeffrey R. Carter
2016-04-07  7:10       ` ahlan
2016-04-05 16:19 ` G.B.
2016-04-06  8:19   ` ahlan
2016-04-06 10:17     ` G.B.
2016-04-06 11:44       ` Dennis Lee Bieber
2016-04-06 20:41         ` Niklas Holsti
2016-04-06 20:54         ` Randy Brukardt
2016-04-06 20:47       ` Randy Brukardt
2016-04-06 21:01         ` Randy Brukardt
2016-04-06 21:22           ` Dmitry A. Kazakov
2016-04-07  7:27             ` Randy Brukardt
2016-04-06 11:37 ` AdaMagica
2016-04-06 13:44   ` ahlan
2016-04-06 14:09     ` Mark Lorenzen
2016-04-06 14:10     ` G.B.
2016-04-06 20:53     ` Stefan.Lucks
2016-04-06 21:03       ` Randy Brukardt
2016-04-06 21:12       ` Niklas Holsti
2016-04-06 21:30       ` Randy Brukardt
2016-04-07  9:56         ` Stefan.Lucks
2016-04-07 16:08           ` AdaMagica
2016-04-07 23:02             ` Randy Brukardt
2016-04-08  7:32               ` Dmitry A. Kazakov
2016-04-07  7:52       ` Georg Bauhaus
replies disabled

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