Identity vs equality (was Re: [Newbies] Assignment)
nicolas cellier
ncellier at ifrance.com
Fri Aug 10 13:11:45 UTC 2007
Göran Krampe a écrit :
> 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. ;)
>
>
For sure, #== has been used with Symbols which can compare really fast
instead of enumerating characters...
But since in modern Squeak 'Hello' = #'Hello', i'am not sure that old
style optimizations #== don't introduce bugs now...
Nicolas
More information about the Squeak-dev
mailing list
|