Use of == for arithmetic equality (was Re: Posting Fixes)
Andreas Raab
andreas.raab at gmx.de
Tue Feb 14 18:50:15 UTC 2006
Dave Mason wrote:
> Andreas had said that foo == 0 was sometimes the right thing. I have
> difficulty imagining many such cases (and those that I can imagine, I
> think of as kludges), so I'm curious what he had in mind.
Here is an example:
SystemNavigation>>allObjectsDo: aBlock
"Evaluate the argument, aBlock, for each object in the system
excluding SmallIntegers."
| object |
object _ self someObject.
[0 == object] whileFalse: [
aBlock value: object.
object _ object nextObject]
The reason this is correct is that for proxies you want the operation to
be side-effect free and #== is side-effect free and #= may not. In
addition, I sometimes use #== in critical code to bullet-proof against
arbitrarily broken implementations of #= (but that's another rant for
another time).
Cheers,
- Andreas
More information about the Squeak-dev
mailing list
|