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 22:28:25 GMT From: alex@MIMSY.CS.UMD.EDU (Alex Blakemore) Subject: Re: and then Message-ID: <66217@mimsy.umd.edu> List-Id: jnestoriak@vnet.IBM.COM writes: >> At a recent code inspection, someone suggested that I convert a >> series of and's to and then's "for performance". firth@sei.cmu.edu (Robert Firth) writes: > Don't do it. The short-circuit forms "and then" and "or else" are > there to allow you to state that the two conditions must be tested > in the order in which they are written ... > where the code would be incorrect with just "and". for the most part, I agree, but you should consider the case where one branch is much more expensive than the other to compute and its in a tight loop, frequently called primitive or other time critical situation. a frequent candidate is a condition combining a boolean variable or simple expression with a complex function call. then it may well be worth the short circuit operator. if boolean_variable and then complex_function (.. lots of expensive args) the n you cant rely on compiler optimizations to get the same effect unfortunately since the function must be called in case it raises an exception to maintain portablility (I believe). -- --------------------------------------------------- Alex Blakemore alex@cs.umd.edu NeXT mail accepted