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,4c459ff0adb576bc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-04 08:58:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.direct.ca!look.ca!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!news.mindspring.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: Refactoring and Ada Date: Mon, 04 Feb 2002 09:03:44 -0800 Organization: AdaWorks Software Engineering Message-ID: <3C5EBEF0.FFC7D48@adaworks.com> References: <3C5AB0B7.9D75D49A@grammatech.com> <3C5E0ED6.E2D52BD3@adaworks.com> Reply-To: richard@adaworks.com NNTP-Posting-Host: 9e.fc.c5.c8 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 4 Feb 2002 16:57:11 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:19592 Date: 2002-02-04T16:57:11+00:00 List-Id: "David C. Hoos, Sr." wrote: > ----- Original Message ----- > From: "Richard Riehle" > Newsgroups: comp.lang.ada > To: > Sent: February 03, 2002 10:32 PM > Subject: Re: Refactoring and Ada > > > I still prefer renames clauses when only one or two operators need direct > > visibility. Use type can be as dangerous as the full use clause under > > some circumstances. > > > Could you give an example of such a circumstance, Richard? My concern is that use type makes all the operators visible for a given type. I realize the compiler can resolve the overloading issues, so that is not so much of a problem. There are at least two concerns with use type. One is the lack of documentation/traceability when there are multiple types in an implementation. The other is the potential for making an error during maintenance, or even during development. If, we with three packages, Goofy, Mickey, and Minnie, each of which has type defined as Bone, Cheese, and Crackers, respectively we could make all the operators directly visible with, use type Goofy.Bone; use type Mickey.Cheese; use type Minnie.Crackers; Throughout my algorithmic code, I might be applying operators to objects of these types without the lucidity afforded by dot notation I would routinely use for operations. Since all operators are directly visible for all types named in my use type clause, there is some potential for confusion on the part of a programmer who has never seen this program before. No only that. It turns out that the only arithmetic operators I want to allow for objects of type Goofy are addition and subtraction. The only comparison operators I am using are equality and greater-than. It would be a disaster, in the given program if a maintenance programmer were to test for less-than when I wanted greater-than. By coding my declarations so only those operators appropriate to my program are directly visible (i.e., through renaming), I can exert more precise control over the future of that code. I am sure you can see where I am going with this. Certainly, in those cases where I really want all the operators to be directly visible, use type has some virtue. For systems where safety is a concern and where one can take advantage of Ada's control over directly visibility, I think renaming is still a virtuous option. I suppose I am old fashioned, but I still like the package design in which the appropriate operators for a type are explicitly coded, either directly or through a renames, in a nested package so the client of that package can do something such as use Goofy.Operators. This has the effect of making only those operators directly visible that are necessary for the client. I think it also has the effect of making the design more clear, the client units safer, and the code more traceable. Someone once said that "Every political systems contains within it the seeds of its own destruction." The same can be said of good ideas added to programming languages. I rather doubt there is a Beaujolais effect hidden in the use type clause, but I think there can be other problems now and then. We need to consider the full range of options available to us when deciding how to approach visibility issues in Ada. The very fact that we have more than one option for managing visibility is one of the great benefits of using Ada in the first place. Richard Riehle