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,38fc011071df5a27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-06 12:11:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Ideas for Ada 200X Date: 06 Jun 2003 15:10:18 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <6a90b886.0305262344.1d558079@posting.google.com> <3EDCBDF4.1050900@attbi.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1054926615 14978 128.183.235.92 (6 Jun 2003 19:10:15 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 6 Jun 2003 19:10:15 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: archiver1.google.com comp.lang.ada:38770 Date: 2003-06-06T19:10:15+00:00 List-Id: 18k11tm001@sneakemail.com (Russ) writes: > Perhaps I erred in my earlier posts in assuming that certain > principles that apply to C++ also apply to Ada, Yes, that turns out to be the case. > so let me restate my claim. > > In C++, I believe it is true that > > A = A + B > > cannot be implemented any more efficiently than > > temp = A > temp += B > A = temp > > Thus A = A + B could not possibly be as efficient as A += B because > the former requires the construction and destruction of a temporary as > well as an extra copy operation. So although the result is identical > (if properly implemented), the efficiency is certainly not. The point > is that "+=" gets you directly into the left-hand side without having > to "cross the bridge" of an "=". Yes, that is clear. > That much is not controversial, folks. Most good C++ programmers know > it. For a good discussion, see More Effective C++ (1996) by Scott > Meyers, Item 22: Consider using op= instead of stand-alone op. > > Now I had assumed, perhaps erroneously, that the same principle > applies to Ada. *If* it does not, I believe it could only be because, > for whatever reason, "+=" cannot be implemented as efficiently in Ada > as it can in C++. Well, you were proposing a new feature in Ada, so you get to define it however you want. However, Robert Eachus pointed out that to be consistent with other parts of Ada, in particular the way Constraint_Error is handled, it makes the most sense to simply define A += B; to be completely identical to A := A + B; except that A is evaluated only once. If you don't like that definition, you can just say so, and insist on proposing the version that allows more efficient implementation, and therefore allows corrupting A on Constraint_Error. However, your version is even less likely than Robert's to be accepted by the Ada standards group (hmm, I'm not sure zero is really less than nil :). > And please, hold your fire on C++. I agree completely that Ada beats > C++ hands down for safety, readability, maintainability, etc. Ok, good. But remember that part of the reason Ada is safe is that it carefully defines what happens on Constraint_Error. > However, I think you are deluding yourself if you think Ada is more > efficient than C or C++. Here we have to disagree. Clearly both Ada and C++ can define an efficient in-place function Add_Matrix. Standard C++ can then map that to "+=". Standard Ada can't. This affects readability, but not efficiency. In general, since the Ada compiler has more type information to work with, it can be more efficient than C++. -- -- Stephe