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,88858d66e427dbcb X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-10 09:50:53 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!elnk-pas-nf1!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!worldnet.att.net!207.35.177.252!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Short circuit boolean evaluation References: <87f5a614.0311051528.30450c7a@posting.google.com> <3FAAEC34.6E67380D@fakeaddress.nil> In-Reply-To: <3FAAEC34.6E67380D@fakeaddress.nil> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Mon, 10 Nov 2003 12:36:17 -0500 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1068485741 198.96.223.163 (Mon, 10 Nov 2003 12:35:41 EST) NNTP-Posting-Date: Mon, 10 Nov 2003 12:35:41 EST Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:2308 Date: 2003-11-10T12:36:17-05:00 List-Id: Gautier Write-only wrote: > svaa: >>I'm a newbie in Ada, I've worked in several languages, last three >>years I've worked in Delphi (Pascal). > > Welcome to professional programming... > > Well. The efficiency of the "short circuit" is to be relativized, > especially with the processors of the last 10 years where each > condition (that automatically come with the short-circuit) means > a serious slowdown. This "short circuit is faster"-mania is completely > outdated. This is neither universally true, nor false. I know that the discussion is centered around boolean tests here, but a boolean test often includes a function call that returns a boolean value. You cannot unversally state that by always calling the boolean function, that it is going to be just as fast, or faster. You don't know how long that function is going to run (obviously). On the other side of the argument, the embedded folks have pointed out that you _want_ to always invoke those functions (ie. avoid short circuiting) so that you can reliably predict and measure your CPU overhead. This is particularly important when you have a low margin of excess CPU capability. This also improves code path coverage, for testing purposes. Both of these reasons are important for life critical pieces of software. But for any _other_ situation (in the general purpose programming arena), I see following reasons to support short circuit expressions: 1. When the extra clauses are invalid (ie. don't evaluate beyond a short-circuit when a pointer is known to be null, for example) 2. For efficiency (avoid computing unnecessary results, particularly in function calls, where the overhead is known to be large enough to care about). The fact that it exists in the language suggests to me that some folks have valid uses for the construct. When someone starts saying that you must always use, always not use something, then I would have to question the reasoning behind that. Finally, it may also depend upon the portability of the code. Programming to Pentium IV whims may really hurt you on another quite different platform, depending upon the application and the choices made. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg