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-06 16:50:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!feed.news.nacamar.de!news.belwue.de!irazu.switch.ch!switch.ch!news.hispeed.ch!not-for-mail From: Gautier Write-only Newsgroups: comp.lang.ada Subject: Re: Short circuit boolean evaluation Date: Fri, 07 Nov 2003 01:49:56 +0100 Organization: Cablecom Newsserver Message-ID: <3FAAEC34.6E67380D@fakeaddress.nil> References: <87f5a614.0311051528.30450c7a@posting.google.com> NNTP-Posting-Host: dclient80-218-90-97.hispeed.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: newshispeed.ch 1068166204 28860 80.218.90.97 (7 Nov 2003 00:50:04 GMT) X-Complaints-To: news@hispeed.ch NNTP-Posting-Date: Fri, 7 Nov 2003 00:50:04 +0000 (UTC) X-Mailer: Mozilla 4.8 [en] (Windows NT 5.0; U) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:2177 Date: 2003-11-07T01:49:56+01:00 List-Id: 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. You find it in Delphi simply because it was already brought into Turbo Pascal 20 years ago as a marketing argument. It worked well on the PCs of these days and with a non-optimizing compiler like Borland's. You'll find rapidly that most of the time "and" and "or" as complete evaluation is better and some cases like "a_boolean_variable and a_long_function" naturally deserve the "and then", and of course "and then" means clearly a short circuit. No problem there. Think also that a compiler can also optimize much better "and" than "and then". It's also good to see the assembler output and of course perform some comparative timings. You'll be surprised... Generally, what makes more sense "at reading" is also the most efficient. If you want to save microseconds, tune the code... [...] > Standard pascal has full evaluation, but most compilers have an option > for short circuit evaluation, and it's the default one, that should > give a clue. If you think to Delphi, it's wrong: the behaviour is set by an option that you can default to what you want. In fact your program may have a completely different behaviour if the compiler with which you compile it has the checkbox "Complete Boolean Evaluation" set or not (see your own words about side effects...). The {$B+} or {$B-} you can put in the source is not a lot better (especially in include file). This point is surely one of the worse mistakes (out of many) Borland did in its language design. What was a nice gadget at its time has become a burden because you have to put everywhere {$B+}'s or {$B-}'s if you want to obtain a real efficiency. Frankly, "and then" and "or else" are a bit more convenient, aren't they ?... Not that standard Pascal has "and_then" and "or_else" for short circuits. > Programs will have the same result if you change the behavior to short > circuit, but you will save a lot of "then" and "else". > > Well, I'm missing the case of expresions that call functions. If that > function have side efects, you have to evaluate it. I think this is a > bad coding style, but perhaps it's because I usually work with > short-circuit. In this cases you would lose backward compatibility. > Although it could be solved with a pragma. You have little chance to bring Borland's blunders into Ada. The best solution is to wait a bit of time. Borland makes you very nostalgic (I know this feeling), but you will see, it will fade... ________________________________________________________ Gautier -- http://www.mysunrise.ch/users/gdm/gsoft.htm NB: For a direct answer, e-mail address on the Web site!