From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,b0b9a5eaad4ab6eb X-Google-Attributes: gid1164f8,public X-Google-Thread: f8c65,37e683828bae12e2 X-Google-Attributes: gidf8c65,public X-Google-Thread: 1014db,37e683828bae12e2 X-Google-Attributes: gid1014db,public X-Google-Thread: 1008e3,37e683828bae12e2 X-Google-Attributes: gid1008e3,public X-Google-Thread: 109fba,37e683828bae12e2 X-Google-Attributes: gid109fba,public From: bill@cafe.net (Kaz Kylheku) Subject: Re: [++] Tight coding Date: 1998/03/02 Message-ID: #1/1 X-Deja-AN: 330073260 References: <6csl81$rb9@news-rocq.inria.fr> <34F97152.DBF199BD@sds-sportdata.com> <6dcdvp$6oa$1@mainsrv.main.nc.us> Organization: Internet Direct NNTP-Posting-Date: Mon, 02 Mar 1998 09:41:35 PST Reply-To: kaz@cafe.net Newsgroups: comp.sys.dec,comp.lang.c++,comp.lang.c,comp.lang.modula2,comp.lang.modula3 In article , Terry Moore 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.