I disagree. size implemented in terms of do: is quite appropriate. The subclass responsibility is do:. If this doesn't suit SequenceableCollection then size should be implemented as a subclass responsibility in SequenceableCollection, /not/ in Collection.
On Fri, Sep 30, 2011 at 1:12 PM, commits@source.squeak.org wrote:
A new version of Collections was added to project The Inbox: http://source.squeak.org/inbox/Collections-nice.423.mcz
==================== Summary ====================
Name: Collections-nice.423 Author: nice Time: 30 September 2011, 10:12:20.333 pm UUID: 7613573f-6d08-9d4c-9d9e-2eaacff799fe Ancestors: Collections-ul.422
#size and #do: default implementation will cause an infinite loop in every new subclass of SequenceableCollection without any form of warning to the poor programmer.
It's simple to avoid this bad behavior by:
- moving Collection>>size implementation to the sole place where it is used
(LinkedList)
- replacing it with a subclassResponsibility.
=============== Diff against Collections-ul.422 ===============
Item was changed: ----- Method: Collection>>size (in category 'accessing') ----- size "Answer how many elements the receiver contains."
^self subclassResponsibility!
| tally |
tally := 0.
self do: [:each | tally := tally + 1].
^ tally!
Item was added:
- ----- Method: LinkedList>>size (in category 'accessing') -----
- size
"Answer how many elements the receiver contains."
| tally |
tally := 0.
self do: [:each | tally := tally + 1].
^ tally!
squeak-dev@lists.squeakfoundation.org