home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / programm / 3374 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  2.4 KB

  1. Path: sparky!uunet!pipex!bnr.co.uk!uknet!comlab.ox.ac.uk!ke94002
  2. From: ke94002@black.ox.ac.uk (Daniel J Mitchell)
  3. Newsgroups: comp.programming
  4. Subject: Re: Programming by Description of Output...
  5. Message-ID: <1992Dec30.233659.7290@black.ox.ac.uk>
  6. Date: 30 Dec 92 23:36:59 GMT
  7. References: <C01yxr.BGF@phage.cshl.org> <1992Dec30.174004.4168@cs.cornell.edu> <C036t1.KCH@phage.cshl.org>
  8. Organization: Oh, come /on/..
  9. Lines: 46
  10. Originator: ke94002@black
  11.  
  12.  
  13.  This method of programming is usually called 'deriving programs'
  14. -- the original work is Edsger Dijkstra's _A Discipline of
  15. Programming_ (Prentice-Hall, 1976), other books I've read which
  16. are probably worth looking at are _Programming from Specifications_
  17. (Carroll Morgan, Prentice-Hall, and the course book for the course
  18. I just did in exactly this subject.. <grin> ), and _The Science of
  19. Programming_ (D.Gries, Springer-Verlag). (Morgan is more concrete
  20. in it's applications, Gries is more abstract).
  21.  
  22.  To take the example given, sorting, it'd be (in the notation used
  23. in the above, at any rate):
  24.  
  25.  var a:seq_{N} Z; con A; and A=bag a
  26.  a:[true, up a]
  27.  
  28.  This then uses the bag abstraction to ensure the elements remain
  29. constant -- there is no precondition, as the data being used here
  30. specifies everything necessary (ie it's a sequence of numbers), and
  31. the postcondition is that the sequence is an upsequence (ie is
  32. sorted).
  33.  
  34.  This method has some advantages -- if the program is derived
  35. step-by step from the specification to the final code, and each step
  36. is right, then the final code is guaranteed to be correct -- this
  37. is useful in some cases (ie to be sure that, say, a binary search
  38. will find exactly what you want it to find, and not the element one
  39. to the left). Also, the methods used to derive programs are
  40. designed to make it very easy to locate flaws in the derivation if
  41. they exist. 
  42.  
  43.  It also can wind up deriving /very/ elegant algorithms (qv the
  44. longest upsequence problem, covered in Gries and Morgan) for
  45. difficult problems.
  46.  
  47.  The disadvantage, obviously, is that it takes a lot more time than
  48. it would to just write code in the majority of cases..
  49.  
  50.  As to doing it automatically, the only thing I know of is a
  51. language called ML which reputedly is a great deal higher level
  52. than most languages, and comes close to being able to take
  53. specifications of the above form as code. (I think. I'm probably
  54. wrong about that, on reflection..)
  55.  
  56. --
  57. Daniel Mitchell == ke94002@black.ox.ac.uk == bi furry juggler
  58.