Bug: Use of == for arithmetic equality

Marcus Denker denker at iam.unibe.ch
Mon Feb 13 19:18:32 UTC 2006


On 13.02.2006, at 18:37, Dan Ingalls wrote:

> I've been playing around with a new VM (heh, heh) which, for a  
> while, happened not to intern (ie force unique instances of)  
> SmallIntegers. In this case the use of == to mean arithmetic  
> equality will not work properly.  In my opinion, all such  
> occurrences in the system should be eliminated ASAP;  == is not an  
> arithmetic compare in any Smalltalk I know of.  While it may work  
> with small constants, it is simply wrong, and an especially bad  
> example for newbies to see.  Besides failing in certain  
> interpreters, it will fail in Squeak itself if the integers are not  
> small.
>
> I regret that I don't have time to fix these right now.  However,  
> if there is a well-intentioned soul out there, he or she will  
> perhaps find the method below to be quite useful.  It found 165  
> methods in my system with this pattern.
>

The interesting thing is that a quite large percentage of those come  
from the beloved

  someCollection size == 0 ifTrue: []

pattern that lots of people like so much... "calling isEmpty is too  
slow" they will tell you,
(and ifEmpty: is *really* evil). As the main objective is speed, they  
of course don't use #=.

For the newbies: Do not optimize for speed before you have proven  
that it makes sense,
and then *document* the hack. Using a hack by default because is "may  
be too slow" is
not a good idea...

       Marcus






More information about the Squeak-dev mailing list