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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3dbf2f325f33ce35 X-Google-Attributes: gid103376,public From: Robert A Duff Subject: Re: Elimination of "use" clauses Date: 1999/07/13 Message-ID: #1/1 X-Deja-AN: 500563358 Sender: bobduff@world.std.com (Robert A Duff) References: <377B5807.88B875E0@cs.york.ac.uk> <7lh74s$v36$1@nnrp1.deja.com> <7ligdq$c8q$1@nnrp1.deja.com> <7ljb4e$na9$1@nnrp1.deja.com> <7ltus1$ah1@dfw-ixnews19.ix.netcom.com> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 1999-07-13T00:00:00+00:00 List-Id: Richard D Riehle writes: > package Sweet_Tooth is > > type Frozen_Dessert is private; > type Lollipop is (OrangeIce, Fudgecicle, Chocolate_Cream); > > Procedure Create (F : in out Frozen_Dessert); > -- more operations > -- declare an Operators only package > package Ops is > function "=" (L, R : Lollipop) return Boolean > renames Sweet_Tooth."="; > function ">" (L, R : Lollipop) return Boolean > renames Sweet_Tooth.">"; I used to like this idea, but I've seen nasty bugs caused by it. Imagine if that last ">" were replaced with "=" due to a cut-and-paste error. It's hard to notice such a bug by reading the code, because as soon as you see "package Ops is" followed by "function ">"", you already know (or *think* you know) what comes next, so you don't read it carefully. And when you're reading someplace else that calls "<", you obviously think it's calling something called "<". The "use type" clause is safer. > This package has the advantage of exporting, through a use clause, only > the operators you want unless you decide to make others explicitly > visible. The client of the package has an easy way to achieve the > necessary visibility. It is a better option than use type because it > only makes visible a restricted set of operators. Good point. I wouldn't mind having a concise way of saying (eg) "T is an integer type with just "+" and "-" operators. But I still prefer "use type" to "package Ops". >... Also, it allows one > to design new behavior for some operators while implementing others > through a simple renames clause. It seems like a dangerous idea to use anything *but* a renaming, if the operator in question is predefined. I mean, if Sweet_Tooth."=" and Sweet_Tooth.Ops."=" do two different things, you're asking for trouble. Maybe I misunderstood what you mean, here. >... With Ada 95 you could create a child package for Sweet_Tooth.Ops > to keep it extensible. I don't understand that point. > Ada's use clause, like the #include of the C family of languages, > is somewhat analogous to wiring your home with uninsulated cable. That analogy is a bit overblown! If you want to insulate something, put it in a package body where it belongs. And surely "use" is not in the same category as "#include". - Bob -- Change robert to bob to get my real email address. Sorry.