[squeak-dev] and:and:and:...

Levente Uzonyi leves at elte.hu
Sat Jan 2 03:51:01 UTC 2010


On Fri, 1 Jan 2010, Randal L. Schwartz wrote:

>>>>>> "Levente" == Levente Uzonyi <leves at elte.hu> writes:
>
> Levente> I agree. I also prefer #and: and #or: against #& and #|, mainly
> Levente> because of better performance. These two are in the ANSI standard so
> Levente> we shouldn't remove them, but replacing their sends with #and: and
> Levente> #or: in the trunk sounds like a good idea.
>
> No.  The semantics of #and: and #or: guarantee short-circuit evaluation, while
> #& and #| always evaluates the argument.  You can't just trade one for the
> other.

Not in theory, but in practice. :)
In worst case replacing #& with #and: could suppress side effects of the 
argument, but users of #& are unlikely to cause side effects intentionally,
though these can be checked one-by-one and the calculations (which 
cause the side effects) can be extracted. It's unlikely that such case 
exists where this extraction is necessary.

I quickly looked at ~50 senders of #& and #| and all of them were written 
with the purpose to omit the parentheses around the logical expression:

foo & bar baz ifTrue: [ ... ]
(foo and: [ bar baz ]) ifTrue: [ ... ]


Levente

>
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
>



More information about the Squeak-dev mailing list