[squeak-dev] Re: What is equivalence? (was: The Trunk: Collections-eem.603.mcz)

Tobias Pape Das.Linux at gmx.de
Wed Feb 4 21:45:59 UTC 2015


On 04.02.2015, at 22:24, Eliot Miranda <eliot.miranda at gmail.com> wrote:

> "similar to" is vague.   I *don't* interpret isFoo methods as isKindOf: (and think that most experienced Smalltalk programmers don't either).  In Smalltalk type = protocol.  So these methods imply that an object implements a given set of messages, not that they are of any given class.

I second this interpretation.
Taking our example at hand[1] we want the otherCollection to have two
a) it should be a collection of object; or differently phrased, have a
   multiplicity >1

b) it needs an internal order (or a half-order may be) and a way to 
   access things via an index.

a is clear but now we question b. Aren't SequenceableCollections the only
thing that fit here? No. I can think of a domain Object, say 
Banquet that is sequenceable (courses), but that I would not call being collection.

So what I would think:

Dictionary new isCollection. "true"
Dictionary new isSequenceable. "false"

OrderedCollection new isCollection. "true"
OrderedCollection new isSequenceable. "true"

Banquet new isCollection. "false"
Banquet new if Sequenceable. "true !"

So what ever we as community expect from a sequenceable should at least in
parts be exhibited by the DinnerCourse, while exhibiting a collection
protocol is unnecessary.[2]


[1]: Original Code
SequenceableCollection>>hasEqualElements: otherCollection
	"Answer whether the receiver's size is the same as otherCollection's
	size, and each of the receiver's elements equal the corresponding
	element of otherCollection.
	This should probably replace the current definition of #= ."

	| size |
 	(otherCollection isKindOf: SequenceableCollection) ifFalse: [^ false].
	(size := self size) = otherCollection size ifFalse: [^ false].
	1 to: size do:
		[:index |
		(self at: index) = (otherCollection at: index) ifFalse: [^ false]].
	^ true
[2]: One _can_ say a banquet is a collection of courses, and indeed, that would be how
     I would implement it (object composition, delegating to an ordered collection) but
     I wouldn't consider it part of the protocol / exhibited interface.

More information about the Squeak-dev mailing list