Bug: Use of == for arithmetic equality

Dan Ingalls Dan at SqueakLand.org
Mon Feb 13 21:40:53 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 #=.

I take issue with the "of course" here.  I defy anyone to demonstrate a significant (even detectable) speedup of == over = between SmallIntegers on any meaningful benchmark.

>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

And for the "pros": 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...
;-)   Dan



More information about the Squeak-dev mailing list