[ENH] Assertion

Andrew P. Black black at cse.ogi.edu
Fri May 26 23:34:42 UTC 2000


Maybe I'm being dumb, but ...

Could someone explain why all of the discussion in this thread has 
assumed that assertions are blocks rather than just being Booleans.

For example, Lex wrote:

>
>Adding an explanation is a great idea.  However, how about using a more
>meaningful word than a generic "with" or "that".  For instance:
>
>	self assert: [ x <= 0 ] explanation: 'x should be positive'

Why should this not just be

	self assert: x <= 0 explanation: 'x should be positive'

Similarly, if you like the alternate style
Stefan  wrote:

>    [a > 0] assert

Why should this not be (a > 0) assert, i.e., make assert a method on 
Boolean, rather than on BlockContext.


One reason for using blocks might be that if a particular class 
overrides assert to be a no-op, then the block need never be 
evaluated, whereas the boolean already would have been.  The costs of 
creating the block, and of sending the assert: message, would of 
course still be there, and they are more often than not likely to 
exceed the cost of evaluating a simple boolean expression.

If we were doing invariants rather than assertions I could see the 
motivation for a block.  Am I missing something fundamental?

	Andrew





More information about the Squeak-dev mailing list