Squeaking trouble

Dan Corneanu cdan at savatech.ro
Tue Nov 15 13:03:31 UTC 2005


Bert Freudenberg wrote:

>
> Am 15.11.2005 um 12:20 schrieb Dan Corneanu:
>
>> Hi,
>> In a SqueakImage 3.8 running on WinXP the ALT+. does interrupt the  loop
>> (for me).
>> I still have a question: why does Collection>>size iterates over all
>> elements and actually counts them?
>>     1. Why is this not implemented with a simple instance variable? or
>
>
> It is, in subclasses where this matters (e.g., Set). Actually, almost 
> all subclasses override #size.
>
Then I see no need for a default implementation of  >>size in Collection
:) .
In most of the cases (correct me if I'm wrong) >>do needs to
know the collection's size. So why not let implementors of >>do assume
they can safely call >>size
without risking to fall into an infinite loop?

>>     2. Why is this not implemented with subclass responsibility?
>
>
> It's the default implementation because so you only have to override 
> #do: in a collection subclass. This default implementation is used, 
> for example, in LinkedList.
>
> - Bert -




More information about the Squeak-dev mailing list