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 08:29:12 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 08:29:11 -0800 Organization: http://groups.google.com/ Message-ID: <5ee5b646.0201040829.18db8001@posting.google.com> References: <3C34BF2C.6030500@mail.com> <3C34D252.4070307@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 1010161751 23519 127.0.0.1 (4 Jan 2002 16:29:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 4 Jan 2002 16:29:11 GMT Xref: archiver1.google.com comp.lang.ada:18537 Date: 2002-01-04T16:29:11+00:00 List-Id: Hyman Rosen wrote in message news:<3C34D252.4070307@mail.com>... > Frank J. Lhota wrote: > > > The situation is quite similar in C/C++; if you use the siumpler & and | > > operators, they do not short-circuit. In either C/C++ or Ada, experienced > > programmers know what needs to be done in order to get short-circuiting. > > > In C/C++ "everyone" knows that & and | are for bit twiddling and && and || > are for combining logical expressions. 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. If you think, as apparently you think C programmers think, that all combination of logical expressions should be done using the more verbose operator (about twice as long in both C and Ada) then always use "and then" and "or else". This is more or less the philosophy in GNAT (the one exception is when logical variables are combined, and indeed in C it is reasonable if Is_Undefined and Is_Unsafe are booleans to say if (Is_Undesigned | Is_Unsafe) then Indeed with some not very clever C compilers, the above will give significantly better code than using || :-) > But get away from C/C++ for a moment. In pure Ada terms, isn't it less safe > for the defaults to be "and" and "or" instead of "and then" and "or else"? Defaults? What are you talking about? There are two operators, one is called AND and one is called AND THEN, and neither is chosen by default, you use the one you want. Exactly the same as in C, where you use either & or &&. You claim that the difference is that in C everyone knows which to use, and think that this is not the case in Ada, but is it not the case that you are simply saying you are more familiar with C than with Ada? Which may of course be true, but does not lead to an even playing field analysis. This is in fact a place where C and Ada take a very similar approach, both providing a more verbose operator for the short circuiting case. As in C, the AND in Ada can also mean bit wise AND (like &) as well as being used for combining boolean values. I do think there is an argument for making AND mean short circuiting, and having a separate operator for bit-wise AND. I would apply the same argument to C, and say that it would have been better if the normally used and/or were spelled & | instead of the awkward && and || (yes, I know, && and || seem "perfectly natural" since you have used them so long, sort of like English spelling seems logical to those who have had to deal with it for ever :-)