Comments (RE: [ENH][ANSI] Collection>>allSatisfy:)

Marcel Weiher marcel at metaobject.com
Wed Jul 5 16:08:53 UTC 2000


> From: "Ivan Tomek" <ivan.tomek at acadiau.ca>
> One opinion, for example, is that a method comment of a non-
> obvious method should state pre- and post-conditions.

Well, it turns out that I just copy-pasted the method body from  
#anySatisfy: and modified it to do the inverse operation.  However,  
when I read the comment of the original method, I decided to replace  
it.  Here is the original method body including the comment:

anySatisfy: aBlock
	"Evaluate aBlock with the elements of the receiver.
	If aBlock returns true for any element return true.
	Otherwise return false"

	self do:[:item | (aBlock value: item) ifTrue: [^ true]].
	^ false

Now, that particular comment is as far as I can tell just a more  
verbose rendering of the method body's code.  My intent was to cut  
out the description of the process used and focus on what it is  
supposed to do, although one could argue that even that wasn't  
necessary and that the name was sufficient.  So probably the best  
thing would have been to eliminate the comment.

The only thing I thought was non-obvious was the behavior of the  
code for an empty collection (for the #allSatisfy: code, not the  
#anySatisfy: shown above), which is to report true.  The code  
actually does this, but more as a side effect and it isn't obvious  
from the code wether that side effect is really intentional (it is)  
or just sort of happens.

Anyway, this is what ANSI says:

Synopsis
	Return true if the discriminator evaluates to true for every  
element of the receiver.
	Otherwise return false.
Definition: <collection>
	Return true if the discriminator evaluates to true for every  
element of the receiver.
	Return true if the receiver is empty.
	Otherwise return false.
	It is unspecified whether the discriminator will be  
evaluated with every element
	of the receiver.

Marcel





More information about the Squeak-dev mailing list