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