Bug: Use of == for arithmetic equality

Colin Putney cputney at wiresong.ca
Mon Feb 13 21:53:45 UTC 2006


Marcus Denker wrote:

> 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 #=.

It could be premature optimization, but then again it could be lack of 
familiarity with the idiom. The above snippet is a straight translation of

if (someCollection.size() == 0) {}

which is pretty common practise in curly-brace languages. Of course, if 
curly-braces are what you're used to, sending #== rather than #= is an 
easy mistake to make.

I've been writing a fair amount of javascript lately, and been bitten by 
the reverse mistake, doing assignment when I want to test for equality.





More information about the Squeak-dev mailing list