Identity vs equality (was Re: [Newbies] Assignment)

Göran Krampe goran at krampe.se
Fri Aug 10 08:32:06 UTC 2007


Hi!

(cc to squeak-dev)

>> All the character is unique so is better (faster) to use #==.
>
>   This is not true for Characters whose code is bigger than 256.
>
>   To me, the identity comparison is more or less in the "meta" level
> or touching implementation details.  Unless you eally need to check
> the "identity" for a good reason, you should always use #= for
> comparison, I think.  (Some performance critical potion of code could
> be exempted... but it should still be limited very carefully.)
>
> -- Yoshiki

Just wanted to mention that this came up on IRC the other day and IMHO one
can generally go by this rule - use #= for equality and only use #== if
you actually *intend* to check for identity. It is slightly poor style to
use #== just to gain a bit of speed, when you in fact *mean* equality.

If we generalise the rule is - program by intention as much as possible
and instead focus on Compiler and friends for speed tricks. :)

It might be interesting to hear what Bryce thinks about this - could for
example Exupery get "tricked" by using #== when you actually mean #= and
actually end up making slower code than if the developer had used #=?

In this particular case it may very well be so that identity checks are
faster than any conceivable equality check - but who knows. :)

regards, Göran

PS. Sure, I have also broken this rule, no doubt about that. ;)



More information about the Beginners mailing list