comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus@futureapps.de>
Subject: Re: Structured exception information
Date: Sun, 28 Jan 2007 19:50:21 +0100
Date: 2007-01-28T19:50:15+01:00	[thread overview]
Message-ID: <1170010221.6748.194.camel@localhost.localdomain> (raw)
In-Reply-To: <uy7nomj1d.fsf@stephe-leake.org>

On Sat, 2007-01-27 at 13:17 -0500, Stephen Leake wrote:


> In addition, you have ignored the problem that each version of
> Write_Output for different hardware will need need a corresponding
> version of the exception type; more work.

Versions of Write_Output for different hardware might also
need a different string passed with the exception? For example
in order to clearly indicate which hardware is reporting.
I'm not so sure a different type is needed for every
variation in hardware. A serial number component might do,
if the hardware is sufficiently similar.

It _is_ more work to write good state/error reporting
modules. But there are some things in Ada that support
"message management" quite well, from a project point
of view I think. One of these is the case coverage rules.
(Exception types would make this even more integrated.)
If a message has an ID of some enumeration subtype,
it is unique per program or library.

Once you have the message types, starting e.g. with

   type Diagnosis is
      (Hardware,
       Parameters,
       Connection,
       ...);

you can construct aggregates of messages. A simple case is when
the messages are indeed string literals, possibly in different
languages. (This setup can be extended to include typed
information from the exception origin, formatting, and more.)

   type List_Of_Messages is array(Diagnosis) of String_Ptr;

   type I18N_Messages(language: ISO_639) is
      record
         texts: List_of_Message;
      end record;

   Japanese_Messages: constant I18N_Messages(Language => JP) :=
      (texts =>
       (Hardware => new String'("..."),
        Parameters => new String'("..."),
        ...);

You can now easily construct translations that are type checked:
Write a simple program that shapes the strings of a
List_of_Messages for Qt linguist XML, or Excel, or GNU gettext etc..
(IIRC, http://www.mckae.com/xia.html has a module for
transforming Ada objects to XML.)
Have someone translate the messages using for example the
Qt linguist tool, output will be XML again.
Then use a simple XSL program to create another
Ada declaration from the XML, for the tranlated messages.
(You won't need to link Qt to your program; you just use
the very comfortable tool - or your favorite XML editor,
and then run the XSL program. Or write the message translations
using Ada directly.)

The Ada compiler checks coverage. The translations should
therefore have one string for each value of the Diagnosis type.

For this procedure to work, you won't even need most of your
program because the strings are collected in one place. They are
not the result of scanning the entire program for possible
message strings.

If you use the linguist program, this points to a possible way
of including additional information like the device name
or errno using %1, %2, ... message forms similar to sprintf
format strings, and similar but not equal to GNU gettext:
Suppose there is an exception type hierarchy.

   type Device_Error(What_Happened: Diagnosis) is
      new Predefined_Exception_Type with
      record
         Device_Name: String(1 .. 12);
         errno: C.int;
      end record;

Then,

   The_Messages: constant List_of_Messages_Ptr :=
      Japanese_Messages'access;

For a command line tool,

   procedure Show_Error(Issue: Device_Error'class) is
      Text: String_Ptr renames
         The_Messages.texts(Issue.What_Happened);
      -- say, "can't open device %1 : %2"
   begin
      Fill_In(Text, Issue);
             -- %1 is filled using Issue.Device_Name
             -- %2 is filled using Issue.errno
      Output_Device.Show(Text);
   end Show_Error;

or, ignoring the text messages entirely,

   procedure Show_Error(Issue: Device_Error'class) is
      Alarm: Sound;
   begin
      Interpret(Issue, Result => Alarm);
      Midi.Play(Alarm);
   end Show_Error;

That is, messages are not frozen where the exception
is raised, but where they are displayed, played, read,
where they turn the red lights on, and the sirens too etc..


> Hmm. With the choice of names you used in Set_Error, you seem to be
> implying that there is a "general error description language", that
> Set_Error can enforce. I don't think that's true.

I think every application has a few classes of errors.
For every class, have a small tree of parameterized
exception information types, as outlined above.


> I guess by "validation" you mean the check "user_volts > Max_volts",
> and the Check_* procedures I quoted above.

Yes.

> > when the *message* should change even though the validation didn't
> > change. From this viewpoint Write_Output mixes two separate
> > concerns: input checking and UI message construction.
> 
> People keep saying those should be separate concerns, but I don't
> accept that. Why is it _better_ that they be separate?

Depending on the type of program, using MVC and corresponding
typed objects might be too complex, unnecessary work, etc.
But once you have a package of reporting routines, it's not
that much work. Typed exception information will help in
creating variants of these.

>  Formatting a string is the best
> way to do that.

Right, a string that explains the issue to the user. But
the string need not be produced by the program, as I've shown
in another post about LEDs with a legend.

Why is it better to have this setup that seems more complicated?
(Isn't it strange to hear an Ada programmer ask why it is
better to not just lump information into a string? :-) :-)
Now who best writes the messages (1), what should be included (2),
and where in the program should they be formatted(3)?

(1) Programmers tend to leave out necessary context information
judging by the brief shouts of command line tools that have
caused so much anger and Google searches for explanations.
Natural language experts aren't usually available during
development, so it seems an advantage to add another level of
indirection, just provide the information, and delegate the
formulation of messages to the domain experts.

(2) How can a programmer anticipate how the information
"raised" from his/her module is best used elsewhere?
E.g., MS recommends not to show stack traces from failing
ASPx programs to end users. Perhaps show a nice page with
some error code and an invitation to report or come back
later.  But what can an Ada exception handler do here
if all exception information is already frozen inside
a string? Parse it?

(3) As you have explained, SPO sentence construction rules are
not universal. The usual approach is therefore to use sprintf-
like procedure calls for message construction. Yet, whatever the
grammar rules of a natural language might require, the
information available *for* message construction is unchanged
by the fact that it can be turned into a sentence. So why not
create or extend a type for the information and pass objects
of the type, not formatted strings?


A related example. I find it quite helpful to see how two
different compilers analyze my programs, hence how different
groups of people create messages. When one of the compilers says,

foo.ada: ... P(x) is not appropriate

The other might say

foo.ada: ... P(x) can only be used if Q(x)

Granted these are messages from different compilers and not
really exception messages. Still, chances are that some Q*(x) is
available to the first compiler, too, because it reports
an error for the same input, without informing about Q*(x).
It's just a Not.
This shows the importance of messages: Good messages can create
huge savings, by reducing the time consuming and frustrating work
of finding out *why* P(x) is not appropriate in the first
error message. Avoids anger, too. 
Suppose now that you had a compiler where you could augment error
messages yourself, without touching the compiler. Example:

foo.adb:18: invalid prefix in selected component "FOO"

where FOO does _not_ denote the component. Suppose further that
this error message had a unique ID, e.g. i_p_s_c_2.
The compiler user can now associate hints with the message
by writing a corresponding statement such as

   for Message_Hints use
       I_P_S_C_2 := "The identifier shown could be the prefix";
   end;

In summary, then, I would prefer the separation of typed exception
data and exception message strings. The first is far more flexible
and accessible for anyone but the lazy programmer who writes
the exception message strings after "with" ;-)


> > or a Spanish character set. 
> 
> I think that is a valid objection; other parts of this thread have
> talked around it. My application has no (current :) requirement for
> this, so I can ignore it.

That's common practice I guess.
For many programs I wouldn't waste time on more sophisticated
reporting, too. But this luxury fails once the assumptions
change, or the requirements ask for more :-)






  parent reply	other threads:[~2007-01-28 18:50 UTC|newest]

Thread overview: 181+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-15 13:44 Structured exception information Maciej Sobczak
2007-01-15 17:17 ` claude.simon
2007-01-16  9:04   ` Maciej Sobczak
2007-01-16 22:39     ` Randy Brukardt
2007-01-15 17:28 ` Robert A Duff
2007-01-15 18:29   ` Georg Bauhaus
2007-01-15 19:44     ` Dmitry A. Kazakov
2007-01-15 20:06       ` Georg Bauhaus
2007-01-15 21:56         ` Randy Brukardt
2007-01-15 22:32           ` Robert A Duff
2007-01-16 18:36             ` Ray Blaak
2007-01-16 19:18               ` C# versus Ada (was: Structured exception information) Georg Bauhaus
2007-01-16 23:29                 ` C# versus Ada Markus E Leypold
2007-01-18 10:22                   ` Dmitry A. Kazakov
2007-01-17 18:14                 ` C# versus Ada (was: Structured exception information) Ray Blaak
2007-01-16 23:27               ` Structured exception information Markus E Leypold
2007-01-17  7:28               ` Martin Krischik
2007-01-16 22:36             ` Randy Brukardt
2007-01-17 16:12               ` Bob Spooner
2007-01-17 23:42                 ` Randy Brukardt
2007-01-16  9:11           ` Dmitry A. Kazakov
2007-01-16 10:45             ` Maciej Sobczak
2007-01-16 13:26               ` Dmitry A. Kazakov
2007-01-16 14:44                 ` Maciej Sobczak
2007-01-16 15:15                   ` Dmitry A. Kazakov
2007-01-16 17:50             ` Jeffrey Carter
2007-01-16 18:31               ` Dmitry A. Kazakov
2007-01-16 22:52                 ` Randy Brukardt
2007-01-17  8:58                   ` Dmitry A. Kazakov
2007-01-17 18:38                     ` Jeffrey Carter
2007-01-17 23:18                       ` Randy Brukardt
2007-01-17 23:46                         ` Robert A Duff
2007-01-18  6:34                         ` Jeffrey Carter
2007-01-19  7:34                           ` Randy Brukardt
2007-01-19 13:52                             ` Dmitry A. Kazakov
2007-01-19 18:57                               ` Jeffrey Carter
2007-01-19 19:57                                 ` Robert A Duff
2007-01-20 20:59                                   ` Jeffrey Carter
2007-01-18  9:55                       ` Dmitry A. Kazakov
2007-01-18 18:28                         ` Jeffrey Carter
2007-01-17 23:36                     ` Randy Brukardt
2007-01-18 10:16                       ` Dmitry A. Kazakov
2007-01-15 22:19     ` Robert A Duff
2007-01-16 13:12       ` Georg Bauhaus
2007-01-15 22:42 ` Adam Beneschan
2007-01-15 23:22   ` Robert A Duff
2007-01-16  6:03     ` tmoran
2007-01-16 13:30 ` Stephen Leake
2007-01-16 14:33   ` Maciej Sobczak
2007-01-16 14:45     ` Georg Bauhaus
2007-01-16 17:54     ` Jeffrey Carter
2007-01-16 22:55       ` Randy Brukardt
2007-01-17 12:10     ` Stephen Leake
2007-01-17 14:05       ` Maciej Sobczak
2007-01-19  9:47         ` Stephen Leake
2007-01-19 11:03           ` Dmitry A. Kazakov
2007-01-20 15:04             ` Stephen Leake
2007-01-21 10:40               ` Dmitry A. Kazakov
2007-01-23  7:28                 ` Stephen Leake
2007-01-23 14:21                   ` Dmitry A. Kazakov
2007-01-25  2:39                     ` Stephen Leake
2007-01-19 13:36           ` Maciej Sobczak
2007-01-20 15:33             ` Stephen Leake
2007-01-20 16:33               ` Robert A Duff
2007-01-21 22:42                 ` Stephen Leake
2007-01-21 23:45                   ` Robert A Duff
2007-01-22  9:14                     ` Maciej Sobczak
2007-01-23  7:33                     ` Stephen Leake
2007-01-23 15:07                       ` Robert A Duff
2007-01-23 15:54                         ` Maciej Sobczak
2007-01-23 17:10                           ` Robert A Duff
2007-01-23 23:59                       ` Randy Brukardt
2007-01-22  9:28               ` Maciej Sobczak
2007-01-23  9:46                 ` Stephen Leake
2007-01-23 14:18                   ` Maciej Sobczak
2007-01-25  2:32                     ` Stephen Leake
2007-01-25  8:53                       ` Maciej Sobczak
2007-01-26  9:35                         ` Stephen Leake
2007-01-26 11:16                           ` Markus E Leypold
2007-01-26 13:46                           ` Georg Bauhaus
2007-01-27 18:17                             ` Stephen Leake
2007-01-28 12:38                               ` Simon Wright
2007-01-28 12:39                               ` Simon Wright
2007-01-28 13:18                               ` Stephen Leake
2007-01-28 15:44                                 ` Georg Bauhaus
2007-01-28 21:48                                 ` Ray Blaak
2007-01-28 18:50                               ` Georg Bauhaus [this message]
2007-01-30  2:15                                 ` Stephen Leake
2007-01-31 18:58                                   ` Georg Bauhaus
2007-02-01 12:20                                     ` Stephen Leake
2007-02-01 14:17                                       ` Georg Bauhaus
2007-01-25 21:52                       ` Randy Brukardt
2007-01-24  0:10                   ` Randy Brukardt
2007-01-24 14:17                     ` Wasteful internationalization (Was: Structured exception information) Alex R. Mosteo
2007-01-24 14:49                       ` Dmitry A. Kazakov
2007-01-24 23:48                         ` Wasteful internationalization Björn Persson
2007-01-25  9:45                           ` Markus E Leypold
2007-01-24 21:03                       ` Wasteful internationalization (Was: Structured exception information) Randy Brukardt
2007-01-25 11:17                         ` Alex R. Mosteo
2007-01-25 21:37                           ` Wasteful internationalization Björn Persson
2007-01-25 21:57                           ` Wasteful internationalization (Was: Structured exception information) Randy Brukardt
2007-01-26  9:13                             ` Dmitry A. Kazakov
2007-01-26 12:12                               ` Georg Bauhaus
2007-01-27  4:09                               ` Randy Brukardt
2007-01-27 17:15                             ` Wasteful internationalization Stephen Leake
2007-01-27 20:44                               ` Markus E Leypold
2007-01-28  0:09                                 ` Björn Persson
2007-01-28  1:08                                   ` Björn Persson
2007-01-28 15:21                                     ` Markus E Leypold
2007-01-29  1:23                                       ` Larry Kilgallen
2007-01-29 19:02                                         ` Björn Persson
2007-01-29 20:19                                           ` Larry Kilgallen
2007-02-01  6:23                                             ` Simon Wright
2007-02-03  0:48                                             ` Björn Persson
2007-02-03  1:04                                               ` Adam Beneschan
2007-02-03 11:52                                                 ` Larry Kilgallen
2007-02-03  2:36                                               ` Markus E Leypold
2007-02-03  2:37                                                 ` Markus E Leypold
2007-02-03 19:59                                                 ` Björn Persson
2007-02-03 20:16                                                   ` Markus E Leypold
2007-02-05 19:26                                                     ` Björn Persson
2007-02-04  4:51                                                   ` Alexander E. Kopilovich
2007-02-05 19:27                                                     ` Björn Persson
2007-02-06  1:32                                                   ` Randy Brukardt
2007-02-06  1:54                                                     ` Markus E Leypold
2007-02-07  1:55                                                       ` Björn Persson
2007-02-07  2:20                                                         ` Markus E Leypold
2007-02-12  1:33                                                           ` Björn Persson
2007-02-12  8:16                                                             ` Franz Kruse
2007-02-12  9:20                                                             ` Not at all wasteful internationalization Martin Krischik
2007-02-12 11:08                                                               ` Georg Bauhaus
2007-02-12 13:02                                                                 ` Martin Krischik
2007-02-07 20:39                                                         ` Wasteful internationalization Randy Brukardt
2007-02-08 13:33                                                           ` Stephen Leake
2007-02-12  2:42                                                           ` Björn Persson
2007-02-06 11:01                                                     ` Peter Hermann
2007-02-06 19:02                                                     ` OT: Flash (was: Re: Wasteful internationalization) Jeffrey R. Carter
2007-02-06 19:40                                                       ` OT: Flash Markus E Leypold
2007-02-03 11:51                                               ` Wasteful internationalization Larry Kilgallen
2007-01-29 18:54                                       ` Björn Persson
2007-01-29 19:03                                         ` Markus E Leypold
2007-01-30 17:46                                           ` Georg Bauhaus
2007-01-30 19:37                                             ` Markus E Leypold
2007-01-30 20:43                                               ` Georg Bauhaus
2007-01-30 20:50                                                 ` Georg Bauhaus
2007-01-30 21:54                                                 ` Markus E Leypold
2007-01-31 11:26                                               ` Alex R. Mosteo
2007-01-31 15:17                                                 ` Markus E Leypold
2007-02-03  0:49                                                 ` Björn Persson
2007-02-03 16:05                                                   ` Alex R. Mosteo
2007-02-03  0:48                                               ` Björn Persson
2007-02-01 12:08                                             ` Stephen Leake
2007-02-03  0:49                                               ` Björn Persson
2007-02-03  9:46                                                 ` Dmitry A. Kazakov
2007-02-03 18:48                                                 ` Stephen Leake
2007-02-03 20:27                                                   ` Björn Persson
2007-01-30  2:20                                       ` Stephen Leake
2007-01-30 10:01                         ` Wasteful internationalization (Was: Structured exception information) Harald Korneliussen
2007-01-19 15:45           ` Structured exception information Robert A Duff
2007-01-20 16:08             ` Stephen Leake
2007-01-20 21:59               ` Robert A Duff
2007-01-19 18:14           ` Ray Blaak
2007-01-19 20:07           ` Robert A Duff
2007-01-20 16:16             ` Stephen Leake
2007-01-20 21:20               ` Ray Blaak
2007-01-21 22:34                 ` Stephen Leake
2007-01-20 22:07               ` Robert A Duff
2007-01-21 10:45                 ` Dmitry A. Kazakov
2007-01-21 23:51                   ` Robert A Duff
2007-01-22 14:39                     ` Dmitry A. Kazakov
2007-01-22 19:02                       ` Robert A Duff
2007-01-23 14:23                         ` Dmitry A. Kazakov
2007-01-29  1:30   ` Brian May
2007-01-16 13:30 ` Structured exception information (task, ANEX E) Martin Krischik
2007-01-16 23:07   ` Randy Brukardt
2007-01-19 16:01   ` Robert A Duff
2007-01-22  7:17     ` Martin Krischik
2007-01-22 19:40       ` Robert A Duff
2007-01-16 15:48 ` Structured exception information Alex R. Mosteo
2007-01-16 18:07   ` Jeffrey Carter
2007-01-17  6:38     ` Duncan Sands
replies disabled

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