<br><br><div class="gmail_quote">On Feb 20, 2008 8:09 AM, Randal L. Schwartz &lt;<a href="mailto:merlyn@stonehenge.com">merlyn@stonehenge.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">&gt;&gt;&gt;&gt;&gt; &quot;goran&quot; == goran &nbsp;&lt;<a href="mailto:goran@krampe.se">goran@krampe.se</a>&gt; writes:<br>&gt;&gt; I&#39;d just do:<br>&gt;&gt;<br>&gt;&gt; removeAll<br>&gt;&gt; self notEmpty ifTrue: [self become: self species new].<br>
&gt;&gt;<br>&gt;&gt; and let subclasses make it more efficient using implementation knowledge.<br><br></div>goran&gt; I would never use become: in &quot;regular code&quot; like this. :)<br><br>First, how &quot;regular&quot; is it if the method hasn&#39;t been missed by anyone<br>
in 27 years. :)<br><br>Second, what are you objecting to? &nbsp;#become: is clearly a part of the image,<br>and works fine. &nbsp;This code also cleans out a grown collection to be the<br>smallest it possiby can become, where delete-one-at-a-time solutions don&#39;t.<br>
</blockquote></div><br><br>#become: and its friends are voodoo. Don&#39;t use them in your code unless you have absolutely no other option.<br><br>It doesn&#39;t work fine. It breaks code that relies on hashes; specifically, a Dictionary elsewhere in your image can start acting screwy if you do a #become: variant that doesn&#39;t preserve an object&#39;s hash. See #becomeForward&gt;&gt;copyHash:. You would then also be relying on a Squeakish behaviour and your code would become less portable across Smalltalk dialects.<br>
<br>They are also a fantastic way to introduce bugs of various sorts, and can even cause an image to crash (as in, stack trace and exit to the OS). Say, for example, that one of the arguments you pass is accidently nil, true or false? Your image would continue working... for a while.<br>
<br>#become: and variants are also very slow and causes the equivalent of a full GC on every invocation.<br><br>Gulik.<br><br clear="all"><br>-- <br><a href="http://people.squeakfoundation.org/person/mikevdg">http://people.squeakfoundation.org/person/mikevdg</a><br>
<a href="http://gulik.pbwiki.com/">http://gulik.pbwiki.com/</a>