comp.lang.ada
 help / color / mirror / Atom feed
From: "Karel Th�nissen" <thoenissen@garabit.nl>
Subject: Re: and then... (a curiosity)
Date: Thu, 4 Sep 2008 17:16:05 +0200
Date: 2008-09-04T15:16:07+00:00	[thread overview]
Message-ID: <48bffbb7$0$74166$dbd49001@news.euronet.nl> (raw)
In-Reply-To: Pine.LNX.4.64.0809041404570.22581@medsec1.medien.uni-weimar.de

<stefan-lucks@see-the.signature> schreef in bericht 
news:Pine.LNX.4.64.0809041404570.22581@medsec1.medien.uni-weimar.de...

>> > Thus, "if X/=0 and Y/X<100" should go into the else-branch, instead of
>> > raising an exception.
>> > The shortcut version "if X/=0 and then Y/X<100" does exactly the right
>> > thing.

>> That would be a very bad idea. With that in place, an exception raised by 
>> a
>> simple programming error, /any/ programming error, would give control to 
>> the
>> else-branch.

> You misread what I wrote. A statement such as "if Y/X<000" should
> definitively propagate an exception for X=0, and I never said anything
> otherwise.

So if I understand you correctly this time, the raising (or not) of an 
exception for "if Y/X<000" should in your view depend on the context where 
it is used: /do not raise/ inside branching conditions of a certain pattern, 
but /do raise/ when used as an ordinary statement. I fear that you 
underestimate the complexities of putting that smartness in a compiler and 
you overestimate the abilities of the ordinary programmers to understand 
what is going on.

No, I do not think I misread. Your writing was not precise: you wrote

   "if X/=0 and Y/X<100" should go into the else-branch, instead of raising 
an exception.

But in Ada it does not go to the else-branche for X=0. So you are proposing 
a language change, and I point out that that would be a vey bad idea.

We cannot expect the compiler to be so smart to distinguish exceptions that 
are avoidable if the left operand had been evaluated first (as with 
conditional boolean operators) from the other exceptions in general. So the 
only viable options are: not doing it like this at all (my choice) or 
picking the else branche for all exceptions. That would make it in invisible 
exception handler. Bad, bad, bad. And as noted above, it would also 
introduce context sensitivity whether exceptions should be raised or not. 
Again very bad.

And if you do want conditional evaluation, you choose 'and then'. What is 
wrong with it? Okay, it is wordy, but the formantics in Ada are very 
precise. That is more important than 5 characters saved.

Maybe you meant 'and' in your example in a more abstract sense without 
providing the precision is demanded by Ada. Unfortunately, you expressed it 
as valid Ada.

> But when "if X/=0 and Y/X<100" propagates an exception for X=0, as, alas,
> done in Ada, something is logically wrong.

So you do think that it should not raise an exception and go to the 
else-branche????? Now what do you want? You contradict yourself. Or this the 
reason you came up with the context dependent interpretation of source code? 
The problem is probably that you use the words 'and' and 'should' in two 
different ways. Seems to be the whole point of this discussion.

How much intelligence do you expect from a compiler? And even if the 
compiler where that smart, would we mere programmers understand what was 
going on. How smart should the compiler be? Should it also start using 
inference, perhaps using whole program analysis?

Computing just is not standard logic. Simple boolean logic will not help us 
out and we should stop looking at mathematics and logic as the holy grail in 
computing. It is a different subject.

> BTW, why do you think that an exception, such as a Constraint_Error,
> should logically count as a contradiction?
>
> Dividing something by zero is undefined, not a contradiction.

That again shows my point that mathematics and computing are two different 
beasts. A mathematician will put the pencil done and stop immediately when 
asked to do an undefined operation, such as a division by zero. That just is 
not an option if you are flying 1000 km/h. Then you raise an exception and 
try to make the best of it, probably working from an unknown or even 
corrupted state, regaining control over the machine and bringing the 
passengers to safety.

If the mathematician were to continue anyway and tried to find his way out 
like our software, he could easily obtain contradicitonary results. This 
should be compared with invariants that are broken because of the reaching 
of an undefined operation/ raising an exception in software.

Comparing undefined/raising an exception allowed because they share the 
property: that the result is neither true nor false:

   false AND raisingAnException => raisingAnException
   false AND contradictionary      => contradictionary

Remember that I introduced this point about contradictions where someone 
(you?) equated ternary logic with Kleene's logic. There are other ternary 
logics.

Just to be nitpicking: coming from a DbC-background, a division by zero 
should raise a *violation* of contract, not an exception. A violation indeed 
is a contraction with the explicitly stated contracts. After a violation 
anything goes.

*Exceptions* should be used for things that can be expected, but that should 
be very rare and that are to hard to handle using standard control 
structures. Think of printers that break down, or network failures.

Groeten, Karel 





  parent reply	other threads:[~2008-09-04 15:16 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-29 21:06 and then... (a curiosity) mockturtle
2008-08-29 21:47 ` Samuel Tardieu
2008-08-30 21:28   ` Maciej Sobczak
2008-08-31  8:28     ` Georg Bauhaus
2008-08-31 23:21       ` Ray Blaak
2008-09-01  8:05     ` Martin Krischik
2008-09-01 17:56       ` Ray Blaak
2008-09-02  6:53         ` Martin Krischik
2008-09-02 14:56           ` Adam Beneschan
2008-09-02 16:28             ` Ray Blaak
2008-09-02 16:26           ` Ray Blaak
2008-09-02 20:50             ` Robert A Duff
2008-09-03 12:35               ` Brian Drummond
2008-09-03 15:56                 ` Robert A Duff
2008-09-04 22:09                   ` Brian Drummond
2008-09-03 21:01               ` Vinzent Hoefler
2008-09-02 14:50     ` Adam Beneschan
2008-08-29 22:28 ` Adam Beneschan
2008-08-30  1:06   ` Jeffrey R. Carter
2008-08-30 11:21   ` Dmitry A. Kazakov
2008-08-30 15:35     ` Peter C. Chapin
2008-09-02 15:06       ` Adam Beneschan
2008-09-02  3:41 ` Steve
2008-09-02  7:48   ` stefan-lucks
2008-09-02  8:57     ` Martin Krischik
2008-09-02 10:50       ` stefan-lucks
2008-09-02 10:33         ` Ludovic Brenta
2008-09-02 13:32           ` stefan-lucks
2008-09-02 12:53             ` Ludovic Brenta
2008-09-02 17:32               ` Georg Bauhaus
2008-09-03 13:14               ` stefan-lucks
2008-09-03 12:44                 ` Dmitry A. Kazakov
2008-09-02 13:39             ` stefan-lucks
2008-09-02 13:40             ` stefan-lucks
2008-09-02 16:48             ` Dmitry A. Kazakov
2008-09-02 17:00             ` Keith Thompson
2008-09-02 19:15               ` Simon Wright
2008-09-02 20:37               ` Robert A Duff
2008-09-02 20:58                 ` Jeffrey R. Carter
2008-09-02 21:08                   ` Robert A Duff
2008-09-03 12:24                     ` Pascal Obry
2008-09-02 22:34                   ` Santiago Urueña
2008-09-03  5:56                     ` Robert A Duff
2008-09-03  6:55                       ` Santiago Urueña
2008-09-03 14:14                       ` Adam Beneschan
2008-09-03  0:11                 ` Randy Brukardt
2008-09-02 17:20             ` Georg Bauhaus
2008-09-04  1:05         ` Stephen Leake
2008-09-04  6:45           ` stefan-lucks
2008-09-04  7:35             ` Dmitry A. Kazakov
2008-09-04 12:04               ` stefan-lucks
2008-09-04 13:00                 ` Dmitry A. Kazakov
2008-09-04 19:05                   ` stefan-lucks
2008-09-04 20:28                     ` Dmitry A. Kazakov
2008-09-05  6:57                       ` stefan-lucks
2008-09-05  6:34                         ` Ray Blaak
2008-09-05 14:14                     ` Robert A Duff
2008-09-05 15:04                       ` Dmitry A. Kazakov
2008-09-07 16:45                         ` stefan-lucks
2008-09-05 15:14                       ` Hyman Rosen
2008-09-05 15:59                         ` Adam Beneschan
2008-09-05 16:10                           ` Hyman Rosen
2008-09-07 16:36                       ` stefan-lucks
2008-09-07 16:08                         ` Gautier
2008-09-04  7:39             ` Karel Th�nissen
2008-09-04 12:12               ` stefan-lucks
2008-09-04 15:13                 ` Georg Bauhaus
2008-09-04 15:16                 ` Karel Th�nissen [this message]
2008-09-04 15:42                   ` Dmitry A. Kazakov
2008-09-04 19:27                   ` stefan-lucks
2008-09-04 19:43                     ` stefan-lucks
2008-09-04 19:40                       ` Georg Bauhaus
2008-09-05  7:00                         ` stefan-lucks
2008-09-05  6:35                           ` Ray Blaak
2008-09-04 20:06                       ` Karel Th�nissen
2008-09-05  7:44                         ` stefan-lucks
2008-09-05  6:41                           ` Vinzent Hoefler
2008-09-04 20:09                     ` Karel Th�nissen
2008-09-05  7:25                       ` stefan-lucks
2008-09-05  6:37                         ` Ray Blaak
2008-09-05  8:20                           ` stefan-lucks
2008-09-05 13:57                         ` Robert A Duff
2008-09-04 16:33                 ` Dmitry A. Kazakov
2008-09-04 19:31                   ` stefan-lucks
2008-09-04 19:59                     ` Karel Th�nissen
2008-09-05  7:27                       ` stefan-lucks
2008-09-05  8:38                         ` Ludovic Brenta
2008-09-04 20:17                     ` Dmitry A. Kazakov
2008-09-05 13:26                 ` Robert A Duff
2008-09-05 13:49                   ` Robert A Duff
2008-09-03  1:24     ` Stephen Leake
2008-09-03  3:31       ` tmoran
2008-09-03 13:22       ` stefan-lucks
replies disabled

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