[ENH] Assertion

Lex Spoon lex at cc.gatech.edu
Sun May 28 20:03:23 UTC 2000


"David N. Smith \(IBM\)" <dnsmith at watson.ibm.com> wrote:
> At 10:50 -0800 5/25/00, Lex Spoon wrote:
> >Stephan Rudlof <sr at evolgo.de> wrote:
> >> >     self failIf: [a > 0]
> >> >     self failIf: [a > 0] with: 'illegal value for a'
> >> >
> >
> >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'
> >
> >-Lex
> 
> It's longer and harder to type, and thus someone is less likely to use an assertion in marginal cases, however I don't like #with: either.
> 

For really simple cases, how about just using a simple assert: without
an explanation?  In particular, an explanation like "x should be
positive" is pointless--programmers can just glance at the code to find
this information.  A more realistic use might be:

	self 
		assert: [ x >= 0 ] 
		explanation: 'the database is corrupt'.


-Lex





More information about the Squeak-dev mailing list