From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,db5c6b2ef47d4b9e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-21 20:10:40 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail From: "DuckE" Newsgroups: comp.lang.ada References: <3B30F836.D700DAA3@raytheon.com> <3B32038D.F1296C79@cadence.com> Subject: Re: short-circuit control forms (& 'long names are doom') X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-Mimeole: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: Date: Fri, 22 Jun 2001 03:10:40 GMT NNTP-Posting-Host: 24.248.45.203 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 993179440 24.248.45.203 (Thu, 21 Jun 2001 20:10:40 PDT) NNTP-Posting-Date: Thu, 21 Jun 2001 20:10:40 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:9020 Date: 2001-06-22T03:10:40+00:00 List-Id: There was an interesting thread on this subject back in 95 (search for short circuit in the Google archives of comp.lang.ada). I found Tucker Taft's comment particularly interesting: ": If both operands are : always evaluated, does that mean that whenever it is unnecessary to : evaluate the second operand, one should use the short-circuit operators : for efficiency? To avoid depending on the quality of your compiler's optimizer, I personally recommend using short-circuit operations by default, and only use "and" or "or" when it is *required* that both operands be evaluated. Of course, a clever optimizer can actually evaluate both operands even though a short circuit is specified, so long as there are no side-effects (including possibilities for exceptions). For example, if A and B are boolean variables, then a compiler might decide it is more efficient to just "and" them together even when "and then" is specified, to avoid the extra conditional branches. Hence, if your compiler is clever, it doesn't matter what you do since it will un-do it if appropriate, and if your compiler is not clever, then using short-circuit by default probably produces somewhat better code quality on average.