home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13441 < prev    next >
Encoding:
Text File  |  1992-09-09  |  6.0 KB  |  131 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!Sirius.dfn.de!ira.uka.de!slsvaat!josef!kanze
  3. From: kanze@us-es.sel.de (James Kanze)
  4. Subject: Re: GOTO, was: Tiny proposal for na
  5. In-Reply-To: rgp@mpd.tandem.com's message of 5 Sep 92 17:31:35 GMT
  6. Message-ID: <KANZE.92Sep9210521@slsvdnt.us-es.sel.de>
  7. Sender: news@us-es.sel.de
  8. Organization: SEL
  9. References: <1992Aug27.181013.29933@spss.com> <rmartin.715102882@thor>
  10.     <1992Aug31.170908.13389@us-es.sel.de> <2388@devnull.mpd.tandem.com>
  11. Date: 9 Sep 92 21:05:21
  12. Lines: 117
  13.  
  14. In article <2388@devnull.mpd.tandem.com> rgp@mpd.tandem.com (Ramon Pantin) writes:
  15.  
  16. > The fact that the literature shows research in the areas of proving program
  17. > correctness doesn't preclude YOU from reasoning in any way you want about
  18. > your program's correctness.  BTW, the research that I've seen is directed
  19. > at mechanically proving things correct, not as thinking aids for programmers.
  20.  
  21. Apparently, I've been misunderstood here.  I was *not* talking about
  22. mechanically proving programs correct, but using some sort of logical
  23. reasoning as a thinking aid.
  24.  
  25. I imagine that, like me, most C++ programmers are involved in
  26. developing real life projects.  We do not have the tools for
  27. mechanical proof available, and if we did, we probably wouldn't have
  28. the time to input the logical specifications necessary to use them.
  29.  
  30. Which, of course, does not mean that we shouldn't try to analyse our
  31. programs logically.
  32.  
  33. > It seems that for some programmers (like me) it is harder to think about
  34. > correctness when we see pascaloid code with lots of state variables, lots
  35. > of places where they are tested and set, lots of indentation as the result
  36. > of not using breaks, continues or returns.  Some other programmers (like
  37. > you and Mr. Martin) prefer to reason about programs that simply avoid all
  38. > the non-SP contructs and replace them with state variables, duplicated
  39. > code and lots of indentation.
  40.  
  41. Interestingly, although it doesn't seem to work in artificially
  42. contrived examples, I find that having to reason carefully about what
  43. my code does tends to reduce the number of indentations, etc.
  44. (Although it may increase the total number of functions.)  I'm not
  45. saying that it's impossible to reason about unstructured code, just
  46. that it's more difficult.  I find it more cost-efficient to structure
  47. the code; any additional time necessary to write it is more than made
  48. up for by the lesser amount of time used in analysis.  (And of course,
  49. the time used in analysis is definitely made up for by the time saved
  50. in error correction.)
  51.  
  52. > >...
  53.  
  54. > >On the other hand, you *cannot* use break or continue, since these mimic a
  55. > >goto to somewhere you *do not* what to go to.  In the same way, how do you
  56. > >prove a function correct if it returns somewhere from the middle.
  57.  
  58. > Very simple, mechanically transform it to SP and then mechanically prove 
  59. > it correct.  How else?  Just run:
  60. >   $ nonsp2sp nonsp.c | prove - nonsp.specs 
  61. >   $ echo $?
  62. >   0
  63. >   $
  64.  
  65. > >Apparently most of the responses have been in favor of using break.  Do I
  66. > >conclude that most programmers just don't care about having correct programs?
  67.  
  68. > Talking about logic, huh?  You can't conclude that!  (Can't use "leaps of
  69. > faith" in logic constructions).
  70.  
  71. (I think I forgot a smiley.  The remark was meant to be partially
  72. humorous.)
  73.  
  74. > There is a big difference between "having correct programs" and being
  75. > able to (or even wanting to) prove those programs correct!
  76. > Your statement indicates that programs that use "break" cannot be correct.
  77.  
  78. No, my statement is that you cannot know that it is correct.
  79.  
  80. > Or to put it your way, the programmers that use break cannot have correct
  81. > programs.
  82.  
  83. > A program can be correct even if nobody can prove it correct.  The truth
  84. > value of a logical proposition doesn't change if individuals that read it
  85. > can't determine its truth value (i.e. if they can't prove it or show a
  86. > counter example).  The world never stopped being quasi-spherical even if
  87. > nobody could prove it, observe it, or believe it.
  88.  
  89. > It is also important to note that most programmers are interested in
  90. > writting correct programs than being able to prove them correct.
  91.  
  92. But then how do they know they are correct?
  93.  
  94. Most programmers I know do want to write correct programs.  And of
  95. course, even with proof of correctness...  Proof of correctness is
  96. just one more arm in the fight.  It's usually a pretty good arm *at
  97. the lower levels*.  (It'll never prove that the customer will be
  98. satisfied with the program, which is what I really want.  It will help
  99. to reduce the price of the program, and also the number of errors in
  100. the delivered program.  My customers tend to consider this a positive
  101. aspect.)
  102.  
  103. > When was the last time that YOU proved one of your "real world" programs
  104. > (at least 10000+ lines) correct?  How long did it take you?  Assuming that
  105. > you have ever done this, how did you felt when, after having proving it
  106. > correct, you found your first bug?  How did you prove that the prove was
  107. > correct (an so on) ?  How did you maintain the prove when you had to
  108. > maintain the program when a set of features was added?
  109.  
  110. See the above comment.  Neither proof of correctness, nor any
  111. structured programming technique, will prove that you've solved the
  112. right problem.
  113.  
  114. I find OO programming and structured programming complementary.  The
  115. OO stuff helps do the high level design stuff, but you still need the
  116. structure and logical reasoning for the low level nitty-gritty, making
  117. sure that each function does what you think it should.
  118.  
  119. In a well defined application, you can expect about one error per
  120. 10000 lines of code using informal proof of correctness (plus all of
  121. the other means at your disposal).  You can do better, but unless the
  122. system is particularly critical, it probably isn't cost efficient.
  123.  
  124. > Think and program as it better fits your brain.
  125. --
  126. James Kanze                         GABI Software, Sarl.
  127. email: kanze@us-es.sel.de           8 rue du Faisan
  128.                                     67000 Strasbourg
  129.                                     France
  130.  
  131.