comp.lang.ada
 help / color / mirror / Atom feed
* Initialization
@ 1990-06-14 16:37 Michael Feldman
  1990-06-14 17:38 ` Initialization Robert Firth
  1990-06-14 19:37 ` Initialization Mike Murphy
  0 siblings, 2 replies; 6+ messages in thread
From: Michael Feldman @ 1990-06-14 16:37 UTC (permalink / raw)


I have a rationale-type questions regarding an apparent irregularity
in Ada, namely in the area of default initializations.

- We know that a _variable_ can be initialized in its declaration, e.g.
   X: T := some_expression;
where some_expression need not even be static. [digression: over-use of
this can be risky IMHO because of nastiness if some_expression manages to
propagate an exception - the point is that initialization is permitted].

- We know that the components of a _record_ type can be default-initialized
in the definition of the record type, e.g.
   type R is record
     F1 : T1 := something;
     F2 : T2 := something_else;
   end record;
where some thing something_else can be e.g. aggregates.

I don't remember having seen any discussion on the group about why other
types cannot be default-initialized, e.g.
   type Little is range -10 .. 10 := 0;
or
   type Vector is array (1..10) of float := (1..10 => 0.0);
or even
   type Vector is array (integer range <>) of float := (others => 0.0);

The last 3 examples are not permitted; it's obvious at least to me that
there would be great benefit in permitting them. What are the costs?

Can someone speak authoritatively about why this irregularity exists? The
Ada Rationale gives a nice justification of default initializations (for
record types, of course) but doesn't say boo about why, if they are so
valuable, they are not allowed uniformly. I'm one of these guys who always
wonders why irregularities in _designed_ languages exist. There is usually
a pretty good reason, but in this case it certainly isn't obvious.
(Irregularities even in natural languages often have good linguistic reasons).

Thanks for whatever enlightenment is forthcoming.
---------------------------------------------------------------------------
Prof. Michael Feldman
Department of Electrical Engineering and Computer Science
The George Washington University
Washington, DC 20052
+1-202-994-5253
mfeldman@seas.gwu.edu
---------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Pre-condition vs. Post-condition
@ 1991-03-24 21:23 stt
  1991-03-25 16:00 ` Arthur Evans
  0 siblings, 1 reply; 6+ messages in thread
From: stt @ 1991-03-24 21:23 UTC (permalink / raw)



Re: Should documentation on exception be preconditions or postconditions

This is pretty much of a style issue in my view, but
I much prefer Norm Cohen's approach for general readability.
That is, document the preconditions for normal action,
and then document the result of violating the preconditions.

I don't see why it really matters whether the exception is raised
explicitly or implicitly, or whether it is a predefined or user-defined
exception, for in Ada, the nearly universal result of violating preconditions 
is an exception, whether you state it or not.

Seeing exceptions as the result of violating preconditions emphasizes
their "exceptional" nature, and properly discourages using
exceptions as a kind of "status code."  A good rule (subject to the
usual exceptions that prove it!) is that any exception raised at 
run-time represents a program bug or an external failure, and the only 
reason to have user-defined exceptions is to provide better diagnostics
in post-mortem debugging of what are essentially unrecoverable errors.

Exceptions might trigger recovery, but probably only at a high level
(e.g., in an interactive program, they would flush the current
activity and reprompt the human operator; in a fault-tolerant system
they might cause the failing task to be decommissioned, or reset
and reelaborated.)

I realize this is a pretty extreme view of exceptions, namely that
they are primarily a debugging tool, not a programming tool, but
it is consistent with the "extreme prejudice" for efficient non-exceptional
execution speed over exception-handling speed.

Another implication of this view of exceptions is that surrounding
a single subprogram call with an exception handler is generally a bad
idea, since it implies that an exceptional condition is in fact
expected to happen!  Further, it implies that design rules stating that
undocumented exceptions should never be propagated are possibly misguided,
since handling "others" and raising some catch-all exception
is throwing away information which may be critical to post-mortem debugging.

Of course, once a subsystem gets to the point of being "fully" debugged,
and is being reused more and more, all exceptions which can be
propagated should be documented, though it may still be more appropriate
to document certain exceptions on a subsystem-wide basis, rather
than trying to identify each individual subprogram which could propagate them.
The exception handler attempting the recovery (if any), probably does
not "know" which particular subprogram call failed anyway, and it
may be more useful to know what is a reasonable recovery strategy
(e.g., how to "reset" the subsystem so as to allow clients to continue
to use it), than to know exactly which subprograms can cause the
subsystem to enter its exceptional state.

Therefore, if an exception is intended to be used for recovery
rather than simply debugging, the most important thing is that
the particular exception raised identifies which subsystem failed,
in what error state (if any) it is now, and what sort of reset
operation is appropriate.  If the exception
simply indicates that a bad parameter was passed in somewhere,
there is probably no obvious recovery strategy other than to
take two aspirin and fire up the source-level debugger in the morning...

S. Tucker Taft    stt@inmet.inmet.com
Intermetrics, Inc.
Cambridge, MA  02138

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1991-03-27 21:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1990-06-14 16:37 Initialization Michael Feldman
1990-06-14 17:38 ` Initialization Robert Firth
1990-06-14 22:28   ` Initialization Michael Feldman
1990-06-14 19:37 ` Initialization Mike Murphy
1990-06-14 22:43   ` Initialization Michael Feldman
  -- strict thread matches above, loose matches on Subject: below --
1991-03-24 21:23 Pre-condition vs. Post-condition stt
1991-03-25 16:00 ` Arthur Evans
1991-03-25 17:05   ` Michael Feldman
1991-03-26  4:31     ` Jim Showalter
1991-03-26 10:21       ` Richard A. O'Keefe
1991-03-27 21:32         ` Initialization Paul Stachour

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