allSeclectors vs. allSelectorsUnderstood
Andrew P. Black
black at cse.ogi.edu
Fri Nov 15 07:45:34 UTC 2002
Does anyone know why Behavior has methods allSelectors and
allSelectorsUnderstood? As far as I can tell, they always answer
essentially the same thing, except that the first returns an
IdentitySet, and the second an Array.
Behavior >> allSelectors
| temp |
superclass
ifNil: [^ self selectors].
temp _ superclass allSelectors.
temp addAll: self selectors.
^ temp
Behavior >> allSelectorsUnderstood (sw 12/01/200)
"Answer a list of all selectors understood by instances of
the receiver"
| aList |
aList _ OrderedCollection new.
self withAllSuperclasses do:
[:aClass | aList addAll: aClass selectors].
^ aList asSet asArray
"SketchMorph allSelectorsUnderstood size"
The coding the second version seems easier to read, but it makes no
sense to build up an OrderedCollection just to turn it into a set. I
propose rewriting as follows:
Behavior >> allSelectors
"Answer a set of all selectors defined by this class and its
superclasses"
| aSet |
aSet _ Set new.
self withAllSuperclasses do:
[:aClass | aSet addAll: aClass selectors].
^ aSet
The only place that allSelectorsUnderstood appears to be used is in
Lexicon (whatever that is). If a client really wants an Array
(rather than a Set) then "aClass allSelectors asArray" would seem to
be a fine idiom; there does not seem to be much justification for
allSelectorsUnderstood to exist as a separate method, and in any case
the "understood" suffix is wrong (these are the selectors _defined_
by the class in question and its superclasses, not understood by it)
and does not capture the distinction (Array rather than Set).
I'm being a bit tentative about this because I think that "sw" is
Scott Wallace, and if so there is probably something much deeper
going on here than I suspect
Andrew
More information about the Squeak-dev
mailing list
|