[squeak-dev] The Trunk: Collections-eem.603.mcz
Eliot Miranda
eliot.miranda at gmail.com
Wed Feb 4 17:17:34 UTC 2015
On Wed, Feb 4, 2015 at 9:07 AM, Chris Muller <asqueaker at gmail.com> wrote:
> isSequenceable is a term that refers to a particular *kind* of
> Collection, a sequenceable one.
>
> Therefore, IMO, I am unable to think of any more clear and explicit
> way of expressing that than "isKindOf: SequenceableCollection"...
>
self isCollection and: [self isSequenceable] is better. isKinfOf: is a)
not object-oriented as it forces an argument to be in a particular
hierarchy rather than having a particular interface, and b) is horribly
inefficient, causing a potentially long search of an object's class
hierarchy. isKindOf: doesn't just smell, it stinks.
So what do you prefer Chris, making isSequenceable an Object method too, or
using self isCollection and: [self isSequenceable]? I like the former
because its simple, but you might have valid objections to extending
Object. That's why I'm canvassing opinions. I wont stop nuking
isKindOf:'s as I see them though ;-)
>
> On Tue, Feb 3, 2015 at 8:59 PM, Eliot Miranda <eliot.miranda at gmail.com>
> wrote:
> >
> >
> > On Tue, Feb 3, 2015 at 12:22 PM, Levente Uzonyi <leves at elte.hu> wrote:
> >>
> >> On Tue, 3 Feb 2015, commits at source.squeak.org wrote:
> >>
> >>> Eliot Miranda uploaded a new version of Collections to project The
> Trunk:
> >>> http://source.squeak.org/trunk/Collections-eem.603.mcz
> >>>
> >>> ==================== Summary ====================
> >>>
> >>> Name: Collections-eem.603
> >>> Author: eem
> >>> Time: 3 February 2015, 12:06:59.618 pm
> >>> UUID: 6521c82f-d8de-4c07-a754-3bc3a8667746
> >>> Ancestors: Collections-mt.602
> >>>
> >>> Three fewer uses of isKindOf:
> >>>
> >>> =============== Diff against Collections-mt.602 ===============
> >>>
> >>> Item was changed:
> >>> ----- Method: Dictionary>>= (in category 'comparing') -----
> >>> = aDictionary
> >>> "Two dictionaries are equal if
> >>> (a) they are the same 'kind' of thing.
> >>> (b) they have the same set of keys.
> >>> (c) for each (common) key, they have the same value"
> >>>
> >>> self == aDictionary ifTrue: [ ^ true ].
> >>> + aDictionary isDictionary ifFalse: [^false].
> >>> - (aDictionary isKindOf: Dictionary) ifFalse: [^false].
> >>> self size = aDictionary size ifFalse: [^false].
> >>> self associationsDo: [:assoc|
> >>> (aDictionary at: assoc key ifAbsent: [^false]) = assoc
> >>> value
> >>> ifFalse: [^false]].
> >>> ^true
> >>>
> >>> !
> >>>
> >>> Item was changed:
> >>> ----- Method: SequenceableCollection>>hasEqualElements: (in category
> >>> 'comparing') -----
> >>> 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 isSequenceable ifFalse: [^ false].
> >>> - (otherCollection isKindOf: SequenceableCollection) ifFalse: [^
> >>> false].
> >>
> >>
> >> This should either include an #isCollection check, or #isSequenceable
> >> should be moved up to Object.
> >
> >
> > Oops. Good catch. Which would you do? I favour the latter.
> >
> >> Levente
> >>
> >>
> >>> (size := self size) = otherCollection size ifFalse: [^ false].
> >>> 1 to: size do:
> >>> [:index |
> >>> (self at: index) = (otherCollection at: index) ifFalse:
> >>> [^ false]].
> >>> ^ true!
> >>>
> >>> Item was changed:
> >>> ----- Method: String>>subStrings: (in category 'converting') -----
> >>> subStrings: separators
> >>> "Answer an array containing the substrings in the receiver
> >>> separated
> >>> by the elements of separators."
> >>> | char result sourceStream subString |
> >>> #Collectn.
> >>> "Changed 2000/04/08 For ANSI <readableString> protocol."
> >>> + (separators isString or:[separators allSatisfy: [:element |
> >>> element isCharacter]]) ifFalse:
> >>> + [^ self error: 'separators must be Characters.'].
> >>> - (separators isString or:[separators allSatisfy: [:element |
> >>> element isKindOf: Character]])
> >>> - ifFalse: [^ self error: 'separators must be
> >>> Characters.'].
> >>> sourceStream := ReadStream on: self.
> >>> result := OrderedCollection new.
> >>> subString := String new.
> >>> [sourceStream atEnd]
> >>> whileFalse:
> >>> [char := sourceStream next.
> >>> (separators includes: char)
> >>> ifTrue: [subString notEmpty
> >>> ifTrue:
> >>> [result add:
> >>> subString copy.
> >>> subString :=
> >>> String new]]
> >>> ifFalse: [subString := subString ,
> >>> (String with: char)]].
> >>> subString notEmpty ifTrue: [result add: subString copy].
> >>> ^ result asArray!
> >>>
> >>>
> >>>
> >>
> >
> >
> >
> > --
> > best,
> > Eliot
> >
> >
> >
>
--
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150204/cdfde2a4/attachment-0001.htm
More information about the Squeak-dev
mailing list
|