Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: bill@cafe.net (Kaz Kylheku)
Subject: Re: [++] Tight coding
Date: 1998/03/02	[thread overview]
Message-ID: <jbCK.1709$Jb.2681517@brie.direct.ca> (raw)
In-Reply-To: T.Moore-0203981541460001@130.123.97.36


In article <T.Moore-0203981541460001@130.123.97.36>,
Terry Moore <T.Moore@massey.ac.nz> wrote:
>In article <6dcdvp$6oa$1@mainsrv.main.nc.us>, scott@softbase.com wrote:
>
>> The best refutation of proofs for programs is in Peter van der Linden's
>> Deep C Secrets. He shows a page from such a proof, which is
>> incomprehensible to anyone other than a theoretical mathematician, and
>> then describes a Usenet flame war about an error in a proof.
>> 
>> There are not enough programmers to go around, and requiring
>> mathematicians to prove programs on top of them will never work.
>
>That is not the way to use proofs of programs. It's much easier
>to develop the proof along with the program, so it's the
>programmer's task, not the mathematician's. You might think
>that proofs add to the time to develop a program, but you must
>remember that finding and fixing bugs is also very time consuming,
>and is not guaranteed to be successful.

I sometimes use a technique which is less powerful than a formal
verification, but powerful nevertheless.

A good program is broken into well defined modules which ``take care''
of some data type. It is of utmost importance that each operation
preserve the integrity of the object of this type which was operated
on. To enforce this, it's possible to write extended check procedures
which can traverse the data structure and verify its integrity,
and adherence to its defining properties.

For example, in some red-black tree code that I wrote, there is a check
procedure which will verify a tree for nearly all of the red-black properties.
It will, for instance, determine that each subtree of a node has the same
``black height'' as its sibling. Thus if some operation fails to preserve this
property, it will be immediately detected. Or if a red node is found whose
children are not both black, again, it is known right away that something went
wrong.  

It is extremely unlikely that some incorrectly written operation would go
wrong in such a way that its results will always satisfy an incorrectly
written check, because the two are written independently and use different
algorithms.

Suppose you wrote an algorithm which generates prime numbers, and checked
its results with another algorithm which tests whether a number is prime.
It is unlikely that you would bugger up both of them in such a way
that the checker validates the results produced by the generator, unless you
had the wrong notion about what a prime number is in the first place.

The penalty is that such checks can raise the running time complexity
of your code and contribute to the code size, so may be too impractical
to include in a ``production'' version of the code. Another drawback is
that you still need high quality test cases in order to exercise the
code and provide good coverage. For example, if a particular variant of a data
structure never occurs due to the nature of the input data, then a flaw in the
construction of that variant will never be discovered.



  reply	other threads:[~1998-03-02  5:00 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-02-23  5:00 Wildfire and NT Robert Harley
1998-02-24  5:00 ` brianh
1998-02-24  5:00   ` Sean Burke
1998-02-25  5:00     ` brianh
1998-02-25  5:00     ` Maynard Handley
1998-02-25  5:00     ` [++] Tight coding (Was: Re: Wildfire and NT) Terje Mathisen
1998-02-28  5:00       ` Piercarlo Grandi
1998-03-01  5:00       ` [++] Tight coding Bill Moyer
1998-03-01  5:00         ` Larry Kilgallen
1998-03-01  5:00           ` [++] Tight coding (comp.sys.dec-only thread) Bill Moyer
1998-03-01  5:00         ` [++] Tight coding Ruud Bruijnesteijn
1998-03-01  5:00           ` scott
1998-03-02  5:00             ` Martin Tom Brown
1998-03-02  5:00             ` Terry Moore
1998-03-02  5:00               ` Kaz Kylheku [this message]
1998-03-02  5:00               ` Pete Becker
1998-03-03  5:00                 ` Ruud Bruijnesteijn
1998-03-03  5:00                   ` Pete Becker
1998-03-04  5:00                     ` Terry Moore
1998-03-03  5:00                       ` Pete Becker
1998-03-04  5:00                       ` Ruud Bruijnesteijn
1998-03-02  5:00             ` Kaz Kylheku
1998-03-02  5:00         ` Peter Moylan
1998-03-02  5:00           ` Martin Harvey
1998-03-02  5:00           ` Scott Fluhrer
1998-03-02  5:00           ` Kaz Kylheku
1998-03-02  5:00           ` Lawrence Kirby
1998-03-02  5:00             ` Peter Moylan
1998-03-02  5:00               ` Ketil Z Malde
1998-03-04  5:00                 ` Lyn A Headley
1998-03-02  5:00               ` Kaz Kylheku
1998-03-03  5:00               ` Lawrence Kirby
1998-03-03  5:00           ` Larry Kilgallen
1998-02-25  5:00     ` Wildfire and NT Mike Albaugh
1998-02-24  5:00   ` Bill Moyer
1998-02-25  5:00     ` Larry Kilgallen
1998-02-25  5:00       ` brianh
1998-02-25  5:00         ` Epiphanies (was: Wildfire and NT) Carlie Coats
1998-02-25  5:00     ` Wildfire and NT John Hascall
1998-02-25  5:00       ` Rob Rodgers
1998-02-24  5:00   ` David Hinds
1998-02-25  5:00     ` Del Cecchi
1998-02-25  5:00     ` brianh
1998-02-25  5:00   ` Bernd Paysan
1998-02-25  5:00     ` brianh
1998-02-26  5:00       ` Doug
1998-02-26  5:00         ` Jeffrey S. Dutky
1998-02-26  5:00       ` Bernd Paysan
1998-02-27  5:00         ` brianh
1998-03-01  5:00           ` Ketil Z Malde
1998-02-27  5:00   ` Paul Kahler
1998-03-02  5:00     ` Joel Gallun
1998-03-02  5:00       ` Przemek Klosowski
read-only archive

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