<br><br><div class="gmail_quote">On Sat, Oct 1, 2011 at 9:54 AM, Bert Freudenberg <span dir="ltr"><<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On 01.10.2011, at 18:33, Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>> wrote:<br>
<br>
> 2011/10/1 Bert Freudenberg <<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>>:<br>
>><br>
>> On 30.09.2011, at 13:05, Nicolas Cellier wrote:<br>
>><br>
>>> 2011/9/30 Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>>:<br>
>>>> 2011/9/30 Bert Freudenberg <<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>>:<br>
>>>>><br>
>>>>> On 29.09.2011, at 19:22, Rodney Polkinghorne wrote:<br>
>>>>><br>
>>>>>> Dear list<br>
>>>>>><br>
>>>>>> I wanted an array that lazily initialized elements 1 to n when you<br>
>>>>>> asked for the nth one. So I ran something like:<br>
>>>>>><br>
>>>>>> SequenceableCollection variableSubclass #Foo ...<br>
>>>>>><br>
>>>>>> When I started a workspace, and tried Foo new: 10, my image hung.<br>
>>>>>><br>
>>>>>> Eventually, I found the problem. The workspace tried to print the<br>
>>>>>> answered instance, which resulted in it being sent a do: message to<br>
>>>>>> print its elements. This ran the method<br>
>>>>>><br>
>>>>>> SequenceableCollection>>do: aBlock<br>
>>>>>> 1 to: self size do:<br>
>>>>>> [:index | aBlock value: (self at: index)]<br>
>>>>>><br>
>>>>>> which ran<br>
>>>>>><br>
>>>>>> Collection>>size<br>
>>>>>> | tally |<br>
>>>>>> tally := 0.<br>
>>>>>> self do: [:each | tally := tally + 1].<br>
>>>>>> ^ tally<br>
>>>>>><br>
>>>>>> which sent do:, which sent size, which ...<br>
>>>>>><br>
>>>>>> Is this considered a bug, or a learning experience for new players?<br>
>>>>><br>
>>>>> The latter. You should not instantiate an abstract class. I don't think there is much that could be done about this.<br>
>>>>><br>
>>>>> - Bert -<br>
>>>>><br>
>>>><br>
>>>> But Foo is a concrete class from Rodney, not Abstract.<br>
>><br>
>> No, it's still abstract since he did not override any methods.<br>
>><br>
>>>> Generally, if the subclass must implement a method, it is expressed<br>
>>>> with an abstract implementation in the upper level<br>
>>>> ^self subclassResponsibility<br>
>>>><br>
>>>> Here, the subclass must implement a message, either #do: or #size but<br>
>>>> there is no explicit guidance.<br>
>>>> Personnally I consider this as very bad kernel code if not a bug.<br>
>>>> Does any subclass really use Collection>>size ?<br>
>>><br>
>>> OK, I just opened an image to check and only one does: LinkedList.<br>
>>> I suggest moving Collection>>size implementation to LinkedList, and<br>
>>> replace it with a subclassResponsibility.<br>
>>><br>
>>> Nicolas<br>
>><br>
>> That would be make the intention more clear, agreed.<br>
>><br>
>> - Bert -<br>
>><br>
><br>
> Eliot objected that #do: is already abstract at Collection level, so<br>
> #size does not have to be.<br>
> An alternative would be to re-implement<br>
> Sequenceable>>size<br>
> ^subclassResponsibility<br>
><br>
> What do others think ?<br>
<br>
</div></div>I thought that's what you meant :)<br>
<br>
Yes, size should be subclass responsibility only for SequenceableCollections, not Collection.<br></blockquote><div><br></div><div>and if so this is tricky:</div><div> SequenceableCollection withAllSubclasses select: [:c| (c whichClassIncludesSelector: #size) == Collection]</div>
<div> => an OrderedCollection(SequenceableCollection LinkedList Semaphore) </div><div><br></div><div>So if added as a subclass responsibility in SequenceableCollection it must be implemented in LinkedList and Semaphore.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
><br>
<font color="#888888"><br>
<br>
- Bert -<br>
</font></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>