home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17931 < prev    next >
Encoding:
Text File  |  1992-12-14  |  3.2 KB  |  74 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: What is Object Oriented Programming? Is C doomed?
  5. Message-ID: <1992Dec14.191812.10567@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec9.191038.16606@thunder.mcrcim.mcgill.edu> <1992Dec10.101100.1@happy.colorado.edu> <1992Dec11.215013.4654@microsoft.com>
  10. Date: Mon, 14 Dec 1992 19:18:12 GMT
  11. Lines: 61
  12.  
  13. In article <1992Dec11.215013.4654@microsoft.com> jimad@microsoft.com (Jim Adcock) writes:
  14. >In article <1992Dec10.101100.1@happy.colorado.edu> srheintze@happy.colorado.edu writes:
  15. >|I believe it was Ed Yourdon who first said:  "it is far easier to optimize a
  16. >|correct (i.e. working) program than correct an optimized program".
  17. >|
  18. >|  (2) What Youdon said was correct?
  19. >
  20. >No, because it is easy to construct correct programs that are practically 
  21. >impossible to optimize and it is easy to construct optimized programs that
  22. >are practically impossible to correct.  The only way to make either correctness
  23. >or optimization "easy" [or even *possible*] is to plan, design and build to
  24. >make both possible from the start.  Given that a program is designed to be
  25. >easy to optimize, and given that a program is designed to be easy to correct,
  26. >then either task becomes easy [or at least *possible*]
  27. >
  28.  
  29.     Actually, I believe the two are intimately related.
  30. Imagine a program with an array access
  31.  
  32.     ... a[i] ...;
  33.  
  34. For the program to operate properly, i must be in bounds.
  35. To ensure an invalid access will terminate the program gracefully,
  36. the compiler inserts a run-time bounds check. This doesnt
  37. make the program correct, nor fast, but it does ensure a certain
  38. class of bugs will be detected at run-time.
  39.  
  40. Now to optimise the program we prove to the compiler that i
  41. *must* be in bounds. Then the compiler will remove the run-time
  42. check, as it cannot be useful.
  43.  
  44.     What have we done? We have simultaneously proved a component
  45. of the program correct (in some sense) and at the same time
  46. optimised it.
  47.  
  48.     (A really smart compiler could do the proof by itself.
  49. In the case of a lazy programmer and dumb compiler, we could just assert that
  50. i is always in bounds---at least the assertion is then explicit
  51. in the code.)
  52.  
  53.     This is the approach A++ takes to things, although C++
  54. turns out to be too complex to reason about .. the idea seems
  55. sensible to me. It is vaguely the same thing that happens in C++
  56. when we cast away const (or some other naughty cast).
  57. (*I* the programmer *know* that this is OK ..)
  58.  
  59.     Or, when a derived pointer converts silently to a base pointer
  60. (*I* the compiler know this is OK --- you dont have to tell me).
  61.  
  62.     Eiffel has formalised this to some extent, at least providing
  63. an assertion syntax (even if the run-time checks cant be optimised away).
  64. Wouldn't C++ benefit from this too?
  65.  
  66.  
  67.  
  68.  
  69. -- 
  70. ;----------------------------------------------------------------------
  71.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  72.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  73. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  74.