comp.lang.ada
 help / color / mirror / Atom feed
From: alex@MIMSY.CS.UMD.EDU  (Alex Blakemore)
Subject: Re: and then
Date: 8 Apr 93 22:28:25 GMT	[thread overview]
Message-ID: <66217@mimsy.umd.edu> (raw)

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

             reply	other threads:[~1993-04-08 22:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-04-08 22:28 Alex Blakemore [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-04-12 18:38 and then Charles H. Sampson
1993-04-12 13:29 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!noc.n
1993-04-11  3:55 Michael Feldman
1993-04-10 19:52 Alex Blakemore
1993-04-10 15:43 Dik T. Winter
1993-04-10 15:36 Dik T. Winter
1993-04-10  9:39 munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!usenet
1993-04-10  1:03 Charles H. Sampson
1993-04-09 18:08 Dave Bashford
1993-04-09 14:06 Dan Rittersdorf
1993-04-08 22:35 Andrew Dunstan,,2285592,
1993-04-08 19:03 Art Duncan
1993-04-08 16:18 Charles H. Sampson
1993-04-08 15:34 Christopher J. Henrich
1993-04-08 12:21 enterpoop.mit.edu!usc!cs.utexas.edu!mars.tsd.arlut.utexas.edu!gardner
1993-04-07 22:58 Mark Lundquist
1993-04-07 21:07 Ray Harwood -- Data Basix: (602)721-1988
1993-04-07 16:21 Charles H. Sampson
1993-04-07 12:42 Robert Firth
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox