comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: about the new Ada 2012 pre/post conditions
Date: Wed, 4 Jul 2012 21:18:24 -0500
Date: 2012-07-04T21:18:24-05:00	[thread overview]
Message-ID: <jt2thn$1hr$1@munin.nbi.dk> (raw)
In-Reply-To: 13hfxjlq0xqtq.x3v8evyf4pku$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:13hfxjlq0xqtq.x3v8evyf4pku$.dlg@40tude.net...
> On Mon, 2 Jul 2012 23:51:19 -0500, Randy Brukardt wrote:
...
>> Legality has nothing to do with preconditions or postconditions.
>
> => It is OK to violate a "contract" defined by these. Here you are.

No, it's not OK; that is the crux of our disagreement. You seem to think 
that the only kind of "contract" is some sort of static thing. But that's 
never, ever been true in Ada.

Exactly. You claim that there cannot be such a thing as a dynamically 
enforced contract. But that's simply bogus - Ada has had those since the 
beginning of time - they were called "constraints". Failing one of these 
checks means that your program is wrong. Ada of course defines what happens 
(raising an exception, etc.), but handling those does not make your program 
less wrong. The only reason that these aren't detected statically is the 
difficulty (and impossibility, in some cases) of detecting them statically.

Yes, of course, there are also exceptions raised for reasons outside of a 
contract (that is, those that don't appear in the profile of a subprogram), 
and handling those might make sense in a correct program.

But handling exceptions raised for contracts does not make the program any 
less wrong; indeed, the only legitimate reasons for handling those is to 
make debugging easier [and, in a few applications, to make the application 
"bullet-proof"].

>> The only kind of correctness checks that *can* exist in general are 
>> dynamic.
>> Ada's entire reason to exist is to include checks like range checks and
>> overflow checks to programs. Without them you get the buffer overflows 
>> and
>> other errors that plague C code.
>
> Yes, but irrelevant. These checks are not contract checks, because,
> otherwise you are in contradiction. No words can change that.

Certainly not if you insist on using an unnecessarily limiting definition of 
"contract".

> But also there are important consequences for software engineering. Since
> these checks have nothing to do with contracts, they must be considered as
> a part of the program semantics and all possible outcomes must be
> *handled*. The problem of buffer overflow is exactly in pretending that it
> cannot overflow. So the program is broken when it does.

That's certainly a fallacy in general. Most Ada programs are best off *not* 
handling exceptions caused by outright bugs, because the Ada runtime will do 
a better job of pinpointing the source of the error than any facility you 
could create yourself. Of course, some programs have to be bullet-proof, but 
that is the tiny minority.

In a sense, of course, it's the Ada runtime that's providing the "handling" 
of those bugs (runtime contract failures). And that means a programmer 
doesn't have to, unless they need bulletproof code that is resistent to 
bugs. A lot of programs are *not* in this category. The Janus/Ada compiler, 
for instance, makes no attempt to handle such bugs -- it's much better to 
abandon the compilation attempt immediately rather than producing a program 
based on guessing what was intended.

>> I suppose you have a totally different definition of "correctness checks"
>> than I do; as usual, we can't have a useful discussion because you have 
>> your
>> own set of terminology.
>
> Terminology is secondary to the semantics. The problem is with the 
> meaning.

Right. I recall in the past that you've been unwilling to grasp the idea of 
bugs being detected at runtime. Just because Ada defines what happens in 
those cases does not suddenly make it OK to introduce bugs into a program.

>> SPARK is next to useless for real programs - at best it can be used only 
>> to
>> prove small parts of a program, and it takes a lot of effort to get 
>> there.
>
> You don't need to prove every possible aspect of the program. The language
> should allow the programmer to choose. Ada 83 had provable contracts 
> stated
> in terms of types. Nothing prevents us from having more detailed contracts
> as well as other program correctness stuff. I simply don't understand 
> where
> is a problem with that.

That's what we're trying to do, and you *obviously* have a problem with 
that. Learning more languages and more tools to do what an Ada compiler 
ought to be able to do is silly.

>> Instead of getting the benefits of building in Ada now,
>> and getting more and more static checks as compilers improve.
>
> I don't see tracking down exceptions as a benefit. Neither would it be a
> for the maintainer to discover that the program suddenly became illegal
> because static checks has been "improved."

That's not a real problem, because any such program is already wrong (its 
depending on the failure of a dynamic contract). Sure, people can write such 
code, but it's just like overlaying objects using address clauses -- it 
might work, but its still wrong and there is no guarentee that a newer 
compiler version will not break such things.

[As an aside, this means you do not want real exception contracts, since 
they cannot usefully be done without having it be implementation-defined 
when an exception is raised by a predefined check. The canonical semantics 
of Ada would require assuming that every line raises Storage_Error, 
Program_Error, and usually Constraint_Error -- that would make it virtually 
impossible to eliminate those exceptions from contracts. OTOH, compilers can 
and do remove most of those canonical checks, and letting the contracts be 
enforced against whatever is actually raised by the generated code would be 
much more useful. But it is impractical to specify the checks that have to 
be removed (and not very helpful - it could only be a very small number), so 
what is raised has to be implementation-defined. Which means that just 
because a contract works on one compiler does not mean that it will work on 
another compiler (including a later version of the same compiler). I agree 
with you that runtime detection of exception contract failure makes no 
sense, so the only choices are implementation-defined or non-existent.]

                               Randy.





  reply	other threads:[~2012-07-05  2:18 UTC|newest]

Thread overview: 125+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-20 13:39 about the new Ada 2012 pre/post conditions Nasser M. Abbasi
2012-06-20 14:02 ` Georg Bauhaus
2012-06-20 14:13 ` Dmitry A. Kazakov
2012-06-20 14:24   ` Nasser M. Abbasi
2012-06-20 14:37     ` Dmitry A. Kazakov
2012-06-20 17:02       ` Georg Bauhaus
2012-06-20 18:28         ` Dmitry A. Kazakov
2012-06-21 20:32       ` Randy Brukardt
2012-06-22  7:23         ` Dmitry A. Kazakov
2012-06-22 11:54           ` Georg Bauhaus
2012-06-22 12:39             ` Georg Bauhaus
2012-06-22 12:43             ` Dmitry A. Kazakov
2012-06-22 14:30               ` Georg Bauhaus
2012-06-22 14:36                 ` Georg Bauhaus
2012-06-22 15:05                 ` Dmitry A. Kazakov
2012-06-22 15:52                   ` Georg Bauhaus
2012-06-22 16:35                     ` Dmitry A. Kazakov
2012-06-22 16:53                       ` Georg Bauhaus
2012-06-22 16:45                   ` Georg Bauhaus
2012-06-22 17:24                     ` Dmitry A. Kazakov
2012-06-22 19:41           ` Randy Brukardt
2012-06-22 23:08             ` Dmitry A. Kazakov
2012-06-23 10:46               ` Georg Bauhaus
2012-06-23 11:01                 ` Dmitry A. Kazakov
2012-06-23 17:46                   ` AdaMagica
2012-06-23 19:23                     ` Dmitry A. Kazakov
2012-06-24 14:59                   ` Georg Bauhaus
2012-06-24 16:06                     ` Dmitry A. Kazakov
2012-06-24 19:51                       ` Georg Bauhaus
2012-06-25  7:48                         ` Dmitry A. Kazakov
2012-06-25 10:10                           ` Georg Bauhaus
2012-06-25  8:08                         ` Dmitry A. Kazakov
2012-06-25 10:17                           ` Georg Bauhaus
2012-06-25 11:54                             ` Dmitry A. Kazakov
2012-06-25 12:39                               ` Georg Bauhaus
2012-06-25 12:51                                 ` Georg Bauhaus
2012-06-25 13:19                                 ` Dmitry A. Kazakov
2012-06-25 16:43                                   ` Georg Bauhaus
2012-06-25 14:08                               ` stefan-lucks
2012-06-25 14:36                                 ` Dmitry A. Kazakov
2012-06-25 14:37                                   ` Dmitry A. Kazakov
2012-06-25 16:26                                   ` stefan-lucks
2012-06-25 19:42                                     ` Dmitry A. Kazakov
2012-06-26 11:50                                       ` stefan-lucks
2012-06-26 13:07                                         ` Dmitry A. Kazakov
2012-06-26 13:49                                           ` Georg Bauhaus
2012-06-26 14:45                                             ` Dmitry A. Kazakov
2012-06-26 16:48                                               ` Georg Bauhaus
2012-06-26 19:43                                                 ` Dmitry A. Kazakov
2012-06-27  8:23                                                   ` Georg Bauhaus
2012-06-27  8:52                                                     ` Dmitry A. Kazakov
2012-06-27 10:30                                                       ` Georg Bauhaus
2012-06-27 12:19                                                         ` Dmitry A. Kazakov
2012-06-27 13:41                                                           ` Nasser M. Abbasi
2012-06-28  7:00                                                             ` Georg Bauhaus
2012-06-27 15:08                                                           ` Georg Bauhaus
2012-06-29 21:03                                               ` Shark8
2012-06-30  8:26                                                 ` Dmitry A. Kazakov
2012-06-30 12:54                                                   ` Niklas Holsti
2012-07-05  2:58                                                   ` Shark8
2012-07-05  7:24                                                     ` Dmitry A. Kazakov
2012-07-06  6:23                                                       ` Shark8
2012-07-06  7:57                                                         ` Dmitry A. Kazakov
2012-07-07  1:09                                                           ` Randy Brukardt
2012-07-07  8:44                                                             ` Dmitry A. Kazakov
2012-06-26 14:54                                           ` stefan-lucks
2012-06-26 15:14                                             ` Dmitry A. Kazakov
2012-07-03  5:28                                           ` Randy Brukardt
2012-07-03 12:53                                             ` Dmitry A. Kazakov
2012-07-03 13:48                                               ` Georg Bauhaus
2012-07-03 14:06                                                 ` Dmitry A. Kazakov
2012-07-03 16:12                                                   ` Georg Bauhaus
2012-07-03 16:45                                                     ` Georg Bauhaus
2012-07-05  1:45                                               ` Randy Brukardt
2012-07-05  7:48                                                 ` Dmitry A. Kazakov
2012-07-05 19:11                                                   ` Adam Beneschan
2012-07-05 19:55                                                     ` Dmitry A. Kazakov
2012-07-06  7:41                                                       ` Georg Bauhaus
2012-07-06  7:47                                                         ` Georg Bauhaus
2012-07-06  8:05                                                         ` Dmitry A. Kazakov
2012-07-06  8:30                                                           ` Georg Bauhaus
2012-07-06  9:01                                                             ` Dmitry A. Kazakov
2012-07-06 11:33                                                               ` Simon Wright
2012-07-06 13:25                                                                 ` Dmitry A. Kazakov
2012-07-06 12:07                                                               ` Georg Bauhaus
2012-07-06 13:37                                                                 ` Dmitry A. Kazakov
2012-07-06 16:17                                                                   ` Georg Bauhaus
2012-07-06 16:34                                                                   ` Georg Bauhaus
2012-07-06 19:18                                                                     ` Dmitry A. Kazakov
2012-07-07  1:24                                                                       ` Randy Brukardt
2012-07-07  9:09                                                                         ` Dmitry A. Kazakov
2012-07-07  1:18                                                                   ` Randy Brukardt
2012-07-07  9:14                                                                     ` Dmitry A. Kazakov
2012-07-07 12:06                                                                       ` Georg Bauhaus
2012-07-07 12:54                                                                         ` Dmitry A. Kazakov
2012-07-07 13:31                                                                           ` Georg Bauhaus
2012-07-03  5:10                                       ` Randy Brukardt
2012-07-03  4:51               ` Randy Brukardt
2012-07-03 12:46                 ` Dmitry A. Kazakov
2012-07-05  2:18                   ` Randy Brukardt [this message]
2012-07-05  8:48                     ` Dmitry A. Kazakov
2012-07-05 12:07                       ` Georg Bauhaus
2012-07-05 12:13                         ` Georg Bauhaus
2012-07-05 12:31                         ` Dmitry A. Kazakov
2012-07-05 18:16                           ` Georg Bauhaus
2012-07-05 19:57                             ` Dmitry A. Kazakov
2012-07-06  6:53                               ` Georg Bauhaus
2012-07-07  0:43                       ` Randy Brukardt
2012-07-07  8:06                         ` Dmitry A. Kazakov
2012-07-07 11:17                           ` Georg Bauhaus
2012-07-07 11:31                             ` Dmitry A. Kazakov
2012-07-07 12:21                               ` Georg Bauhaus
2012-07-07 13:03                                 ` Dmitry A. Kazakov
2012-06-20 19:18 ` Anh Vo
2012-06-20 20:16 ` Jeffrey R. Carter
2012-06-20 20:21   ` Jeffrey R. Carter
2012-06-20 20:51   ` Maciej Sobczak
2012-06-20 21:04     ` Dmitry A. Kazakov
2012-06-20 22:19   ` Robert A Duff
2012-06-21  6:32     ` Georg Bauhaus
2012-06-21 20:37   ` Randy Brukardt
2012-06-21 20:55     ` Jeffrey Carter
2012-06-22 19:15       ` Randy Brukardt
2012-06-21 20:23 ` Randy Brukardt
2012-06-22  7:34   ` Martin
replies disabled

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