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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d2f0af5e440b367f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-15 20:11:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: proposal for new assignment operators Date: Tue, 15 Jul 2003 20:14:24 -0700 Organization: AdaWorks Software Engineering Message-ID: <3F14C30F.52A2010@adaworks.com> References: <3EF9CD5F.6030608@cogeco.ca> <3doRhIgUmUYX@eisner.encompasserve.org> <3F038B77.2F2E41B7@adaworks.com> <1ec946d1.0307070736.2eb5e820@posting.google.com> <3F1209CF.C3907A61@adaworks.com> Reply-To: richard@adaworks.com NNTP-Posting-Host: 41.b2.48.04 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 16 Jul 2003 03:11:01 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:40317 Date: 2003-07-16T03:11:01+00:00 List-Id: Hyman Rosen wrote: > Richard Riehle wrote: > > > Container types, perhaps not those you have created, are often designed > > as limited types. There are different points-of-view on this. I recall > > a PhD dissertation from OSU on this subject where the dissertation > > recommended that all types for a container be limited, even the generic > > formal parameters. > > But this is not how Ada arrays work, so why should other containers > work that way? In C++, the standard containers all support assignment, > with the semantics of making the target of the assignment compare > equal to the source after the assignment happens (which means that the > two containers will have the same size, and the elements will compare > equal). Well, actually, container types constructed from arrays are often designed as limited private. In fact, it is frequently desirable to keep direct visibility to the array away from the client of that array, even when the client knows the underlying structure is an array. > > Exactly. This is one reason for not providing assignment over a limited > > type. Instead, we typically create a copy procedure and declare the > > name of that copy procedure as specifically as possible. > > In C++, that procedure is just called "operator=". We can program > assignment from arbitrary source types if we choose, by using templates. One problem with overloading the assignment operation is that the user of that assignment cannot know, except via the documentation, what the outcome will be. For a limited type, when we declare a procedure, we can give the procedure a name that makes clear the expected outcome. procedure Copy_BitWise(Source : in T; Target : out T); procedure Copy_Shallow(Source : in T; Target : out T); and so forth. While this might seem a little extreme, I rarely encounter anyone who is confused by a procedure where the exact behavior is declared in its name. If we overload assignment, we still find ourselves with no idea of what is really going on when we assign a to b. This is also true of overloading the equality operator for a composite type, particularly one that includes access values in its definition. I prefer limited types, even though they are slightly more work to define, and even though I have to think ahead a lot more when designing with them. Matthew Heaney has correctly pointed out that the idiom is possible in C++. Mr. Rosen has noted that there are places in C++ where the types are roughly equivalent to limited types. Even so, the power of limited types ought not be underestimated as a feature of Ada that encourages the design of safe abstractions. Richard Riehle