From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 8 Apr 93 12:21:25 GMT From: enterpoop.mit.edu!usc!cs.utexas.edu!mars.tsd.arlut.utexas.edu!gardner@ucb vax.Berkeley.EDU (Don Gardner) Subject: Re: and then Message-ID: <1993Apr8.122125.24053@titan.tsd.arlut.utexas.edu> List-Id: sampson@nosc.mil (Charles H. Sampson) writes: >In article <19930406.143008.278@almaden.ibm.com> jnestoriak@vnet.IBM.COM write s: >>At a recent code inspection, someone suggested that I convert a >>series of and's to and then's "for performance". I expect that >>90+% of the time all the conditions will be true anyway. But is >>it really true that and then will get better performance than >>and? I realize this is probably a compiler dependant question. >>Also, I question the value of doing such a thing styllistically. >>Any opinions? > My style is to use the boolean operators generally, reserving the >short-circuit forms to document that the second operand should not be eval- >uated under some circumstances. I humbly suggest that you change your perspective. When I encounter a non-short-ciruit of the boolean operators I ask why both expressions _must_ be evaluated; i.e., the short-circuit forms are the default and the other forms are used only when both expressions must be evaluated. Also, I avoid writing functions that have side effects. Since (as best I can reason at this early hour) both expressions need to be evaluated only when both have side effects, I rarely use the non-short-circuit forms.