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,25aa3c7e1b59f7b5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-04 16:32:07 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dewar@gnat.com (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: A case where Ada defaults to unsafe? Date: 4 Jan 2002 16:32:06 -0800 Organization: http://groups.google.com/ Message-ID: <5ee5b646.0201041632.10be3ca4@posting.google.com> References: <3C34BF2C.6030500@mail.com> <3C34D252.4070307@mail.com> <5ee5b646.0201040829.18db8001@posting.google.com> <3C35E733.6030603@mail.com> NNTP-Posting-Host: 205.232.38.14 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1010190727 3614 127.0.0.1 (5 Jan 2002 00:32:07 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 5 Jan 2002 00:32:07 GMT Xref: archiver1.google.com comp.lang.ada:18570 Date: 2002-01-05T00:32:07+00:00 List-Id: Hyman Rosen wrote in message news:<3C35E733.6030603@mail.com>... > Robert Dewar wrote: > > > Well any vaguely competent Ada programmer should equally > > well know that in Ada "and then" and "or else" short circuit > > > and "and" and "or" do not. > > Sure. But what do you gain from the non-short-circuit ones, > except for the risk that you've used them incorrectly? > > > > Exactly the same as in C, where you use either & or &&. > > > In C, you cannot use & and | in the same way that you use > && and ||, because the former accept only integer operands. > For example, if you have a pair of pointers, p and q, and > wish to test whether both are not null, you must use p&&q. > If you were to use p&q, the compiler would reject it. > > C++ does have the horrible trap that user-defined && and || > operators don't short-circuit. Expert advice is to never > define these except in the rarest of circumstances. No, I am talking about the case of boolean operands. With non-boolean operands you are in a completely different domain. I personally find the usage p&&q here frightful, and think it much better to introduce the explicit null tests. But anyway I am only talking about the boolean case. Why use AND instead of AND THEN, or OR instead of OR ELSE The argument on this side goes like this. We only want to use AND THEN if we specifically want to imply that there is a serial dependence, which we think should be pointed out. If there is no serial dependence, then some people find it cleaner to use AND. After all, if we write A = B and C > D as opposed to A = B and then C > D it is clear that these are semantically equivalent, so a compiler can freely convert one into another, so there is no efficiency issue in many cases. Where there is an efficiency issue, it is often hard for a programmer to tell what is more efficient. Pascal has a more general rule. In Pascal, A and B can be evaluated left to right, right to left, with or without short circuiting, giving the compiler maximum flexibility. P.S. this is a peculiar thread, there is an extraordinary number of very bizarre and misleading posts. I am only responding to posts that are not in this category, but beware :-)