home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / eiffel / 1445 < prev    next >
Encoding:
Text File  |  1993-01-21  |  3.4 KB  |  97 lines

  1. Path: sparky!uunet!mcsun!uknet!mucs!cs.man.ac.uk!mod
  2. From: mod@cs.man.ac.uk (Mike O'Docherty (Teaching Company Associate))
  3. Newsgroups: comp.lang.eiffel
  4. Subject: Re: creation
  5. Message-ID: <mod.727611337@cs.man.ac.uk>
  6. Date: 21 Jan 93 10:15:37 GMT
  7. References: <memo.879182@cix.compulink.co.uk>
  8. Sender: news@cs.man.ac.uk
  9. Lines: 86
  10.  
  11. wil@cix.compulink.co.uk (William Stuart-smith) writes:
  12.  
  13. >mod@cs.man.ac.uk (Mike O'Docherty (Teaching Company Associate))
  14. >writes
  15. >> On page 128 of "Eiffel: The Language", it is stated (in the definition of
  16. >> consistency) that postconditions need not be checked on return from a
  17. >> creation procedure. I see no reason why they they should be let off the
  18. >> hook; is this a mistake?
  19.  
  20. >It seems correct to me. A creation procedure sets up the invariant of its
  21. >class: It returns nothing and affects only its class, therefore the only
  22. >'postcondition' (in the sense of the entire condition which is implied by the
  23. >precondition for correctness) that applies pertains to the state of the class
  24. >as a whole and is therefore the invariant.
  25.  
  26. >Where do you suggest that this would be insufficient, and what 'require'
  27. >clause would you add?
  28.  
  29. class X
  30. creation
  31.     make
  32. feature
  33.     identity: STRING;
  34.  
  35.     make(id: STRING) is
  36.         require
  37.             valid_id: id /= Void and then id.count /= 0
  38.         do
  39.             identity := clone(id);
  40.         ensure
  41.             id_set: equal(identity, id)
  42.         end
  43. end -- class X
  44.  
  45. The next time assertion checking is spelled out is on page 133. Here it is
  46. stated that "The implementation should enable developers to set various
  47. evaluation levels for assertions. ... The possible levels ... are" followed
  48. by a list. Two points in this list worry me:
  49.  
  50.     . ensure: also evaluate postconditions on return from routines of this class
  51.  
  52. [This contradicts the statement on page 128 since a creation procedure is a
  53. routine]
  54.  
  55.     . invariant: also evaluate the class invariant on entry to and return
  56.       from qualified calls to routines of [this class]
  57.  
  58. [Now, you'd better not check the invariant on entry to a routine if it happens
  59. to be a creation procedure called by a creation instruction, otherwise
  60.  
  61. class Y
  62. creation
  63.     make
  64. feature
  65.     identity: STRING;
  66. feature {NONE}
  67.     make(id: STRING) is
  68.         do
  69.             identity := clone(id);
  70.         end
  71. invariant
  72.     valid_id: identity /= Void and then identity.count /= 0
  73. end -- class Y
  74.  
  75. will never run with assertions switched on --- on entry to make, the
  76. `identity /= Void'  part of the invariant is bound to fail!
  77. ]
  78.  
  79. Some clarification/correction is called for in this Chapter. The fact that
  80. `creation procedure' is ambiguous doesn't help --- is it "a routine exported for
  81. use in a creation instruction (and perhaps also for use as a simple procedure"
  82. or "a procedure *being used* to execute a
  83. creation instruction".
  84.  
  85. Sorry, I didn't intend this to turn into a critique of / erratum for ETL, but
  86. I was compiling some code and this chapter had me scratching my head for quite
  87. a while.
  88.  
  89. Mike.
  90.  
  91. -------------------------------------------------------------------------
  92. "Lou Reed was singing about scoring drugs. Tom Robinson was singing about
  93. scoring sex. I don't know what she's singing about, Dolly Mixtures
  94. probably." --- Nicky Campbell on Vanessa Paradis' cover of "Waiting for
  95. the man"   => => => => => => => => => => => => => => =>  mod@cs.man.ac.uk
  96. -------------------------------------------------------------------------
  97.