comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Suggestion for Ada 200x - Interface inheritance
Date: 28 May 2003 18:13:35 -0400
Date: 2003-05-28T18:13:35-04:00	[thread overview]
Message-ID: <wccd6i2yb1s.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 719Aa.14547$fT5.3595@nwrdny01.gnilink.net

Hyman Rosen <hyrosen@mail.com> writes:

> Wesley Groleau wrote:
>  > But that meant adding a throws clause to each of hundreds of files.
> 
> 'Throws' clauses are a really bad idea, the more so because it seems
> so right on first appraisal.

Throws clauses are a bad idea in Java, because they require scattering a
whole lot of useless exception handlers all over the place.  Or else a
whole lot of useless throws clauses.  But I don't think they're a
fundamentally bad idea; I think it would be possible to design a
language without those problems.

One thing Java got right is that there are two kinds of exceptions:
For one kind, you want to declare "this procedure can raise X",
and force callers to either handle it or declare that they throw it.
For the other kind, you don't want to declare anything.

One thing Java got wrong is the some of the exceptions are in the wrong
category.  For example, all the streams operations can throw I/O
exceptions, even though streams are not necessarily tied to I/O.
If an open-file operation is designed to raise a file-not-found
exception, then I think it's reasonable to require the caller to handle
it (or reraise it).  But a read-from-stream operation should not require
any extra mumbo-jumbo at the call site; it might not even be reading
from a file.

I also think you should let the programmer decide which exceptions are
in which category.  For example, an out-of-memory exception
(Storage_Error, in Ada) should, by default, not require any
declarations, since pretty-much anything can raise it.
But in an embedded system, you might want the compiler to prove that
out-of-memory can't happen.  I envision a compiler that calculates (at
link time) a worst-case stack size for every procedure (including called
procedures).  The programmer could say, "on entry to this procedure,
make sure there's enough stack space".  If the procedure is recursive,
or declares something like:

    X: String(1..N);

where N is not known, the "worst case" would be "the size of the whole
address space".  But if you don't do those things, the "worst case"
could be reasonable, and the compiler could prove at compile time (link
time, really) that certain regions of code (perhaps the whole program)
do not run out of stack space.

Consider also something like a generic iterator:

    generic
        with procedure Action(X: Element);
    procedure Set_Iterate(S: Set);
    -- Calls Action once for each element of the Set.

Presumably Set_Iterate can raise whatever exceptions are raised by the
actual procedure passed to Action.  But you don't want to say
Set_Iterate raises "any exception".  You want to say, "Set_Iterate
raises whatever exceptions are raised by Action".  That's not known at
compile time of the generic, but it could be known at compile time of
the instantiations.

So for "throws clauses" to work well, we need some sort of pass-through
concept -- "this throws what that throws".  This would allow abstraction
layers that simply pass exceptions through to avoid saying "throws
anything" and the subsequent clutter in clients.

Another point is that most exceptions are really preconditions.  See
Eiffel, and design-by-contract.  You want to declare not only that this
procedure raises Queue_Empty_Error, but also under what conditions that
exception is raised (e.g. if Is_Empty is True), and that
Queue_Empty_Error gets raised before modifying the queue.

And if you have pre- and postconditions, I think you want to attach
postconditions to exceptional situations.  You want a way to express,
"If this procedure returns normally, then such-and-such is true.  If it
raises File_Not_Found, then so-and-so is true.  And if it raises
Storage_Error, all bets are off (i.e., any data touched by this
procedure might have been damaged, so don't touch it)."

And finally, you want user-settable defaults.  Like, "All procedures in
this package, and all of its descendants, behave such-and-such a way in
the presence of so-and-so exception."

- Bob



  parent reply	other threads:[~2003-05-28 22:13 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-23 23:05 Suggestion for Ada 200x - Interface inheritance Steve
2003-05-24  1:02 ` Robert A Duff
2003-05-29 16:47   ` Brian Gaffney
2003-06-01 10:29   ` Craig Carey
2003-05-24 12:35 ` Wojtek Narczynski
2003-05-24 17:53   ` Georg Bauhaus
2003-05-25 13:11     ` Wojtek Narczynski
2003-05-24 22:07   ` Robert A Duff
2003-05-25 14:12     ` Wojtek Narczynski
2003-05-25 17:53       ` Jeffrey Carter
2003-05-25 18:47         ` Wesley Groleau
2003-05-25 19:42           ` Hyman Rosen
2003-05-26  7:53             ` Wojtek Narczynski
2003-05-26 15:50               ` Hyman Rosen
2003-05-27 18:41                 ` Wojtek Narczynski
2003-05-27 18:55                   ` Wesley Groleau
2003-05-27 19:13                   ` Hyman Rosen
2003-05-28 13:07                     ` Wojtek Narczynski
2003-05-28 13:28                       ` Jean-Pierre Rosen
2003-05-29  0:58                       ` Hyman Rosen
2003-05-28 22:13             ` Robert A Duff [this message]
2003-05-28 23:50               ` Hyman Rosen
2003-05-29  9:17               ` Dmitry A. Kazakov
2003-05-29 13:31               ` Wojtek Narczynski
2003-05-26  7:51           ` Wojtek Narczynski
2003-05-25  1:33   ` Steve
2003-05-25 10:37     ` Simon Wright
2003-05-26  7:54     ` Jean-Pierre Rosen
2003-05-26 10:07       ` Preben Randhol
2003-05-26 16:32         ` Pascal Obry
2003-05-26 16:59           ` Preben Randhol
2003-06-01 10:53       ` Craig Carey
2003-06-01 12:17         ` Preben Randhol
2003-05-26  7:49   ` Jean-Pierre Rosen
2003-06-02  9:01     ` Wojtek Narczynski
2003-05-28 13:57 ` MI in Ada 200X (was: Suggestion for Ada 200x - Interface inheritance) Mário Amado Alves
2003-05-28 15:05   ` Preben Randhol
2003-05-29  0:54     ` MI in Ada 200X Hyman Rosen
2003-05-29 17:38       ` Stephen Leake
2003-05-30  7:20       ` Preben Randhol
2003-05-29  9:17     ` MI in Ada 200X (was: Suggestion for Ada 200x - Interface inheritance) Dmitry A. Kazakov
2003-05-29 22:56       ` MI in Ada 200X Hyman Rosen
2003-05-30  7:39         ` Dmitry A. Kazakov
2003-05-30 13:11           ` Hyman Rosen
2003-05-30 14:29             ` Robert A Duff
2003-05-30 14:51               ` Hyman Rosen
2003-05-30 15:11         ` Mark A. Biggar
2003-05-30 15:51           ` Hyman Rosen
2003-05-30 22:38           ` John Griffiths
2003-05-30  2:50       ` Wesley Groleau
2003-05-30  7:38         ` Dmitry A. Kazakov
2003-05-30 12:20           ` Karel Miklav
2003-05-30 12:59             ` Hyman Rosen
2003-05-30 14:02               ` Georg Bauhaus
2003-05-30 14:04                 ` Lutz Donnerhacke
2003-05-30 18:45                   ` Georg Bauhaus
2003-05-30 15:02                 ` Hyman Rosen
2003-05-30 19:14                   ` Georg Bauhaus
2003-05-30 19:40                     ` Hyman Rosen
2003-05-30 19:31               ` Wojtek Narczynski
2003-05-30 22:42             ` John Griffiths
2003-05-31  9:27             ` Dmitry A. Kazakov
2003-05-31 13:53               ` Martin Krischik
2003-06-01  9:18                 ` Dmitry A. Kazakov
2003-05-30  8:28         ` Mário Amado Alves
2003-05-30  8:46       ` MI in Ada 200X (was: Suggestion for Ada 200x - Interface inheritance) Preben Randhol
2003-05-31 10:17         ` Dmitry A. Kazakov
2003-05-31 13:48           ` Preben Randhol
2003-05-31 17:21             ` Dmitry A. Kazakov
2003-05-29  0:54   ` MI in Ada 200X Hyman Rosen
2003-05-29  2:13   ` MI in Ada 200X (was: Suggestion for Ada 200x - Interface inheritance) Robert I. Eachus
2003-05-29 12:06     ` Mário Amado Alves
2003-05-31 19:58       ` Chad R. Meiners
  -- strict thread matches above, loose matches on Subject: below --
2003-06-02 15:57 Suggestion for Ada 200x - Interface inheritance Lionel.DRAGHI
2003-06-02 18:58 ` Pascal Obry
2003-06-02 19:27 ` Bill Findlay
2003-06-03 17:33 Lionel.DRAGHI
2003-06-03 17:46 ` Vinzent Hoefler
2003-06-03 18:49   ` Bill Findlay
2003-06-03 19:02     ` Vinzent Hoefler
2003-06-03 19:13     ` Vinzent Hoefler
2003-06-03 17:38 Lionel.DRAGHI
2003-06-03 17:47 ` Preben Randhol
2003-06-03 17:48 ` Vinzent Hoefler
2003-06-04 16:22 Lionel.DRAGHI
replies disabled

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