comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Elimination of "use" clauses
Date: 1999/07/13
Date: 1999-07-13T00:00:00+00:00	[thread overview]
Message-ID: <wccr9mc5y47.fsf@world.std.com> (raw)
In-Reply-To: 7ltus1$ah1@dfw-ixnews19.ix.netcom.com

Richard D Riehle <laoXhai@ix.netcom.com> 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.




  parent reply	other threads:[~1999-07-13  0:00 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-01  0:00 Elimination of "use" clauses Dr. Neil C. Audsley
1999-07-01  0:00 ` Joe Wisniewski
1999-07-01  0:00 ` Samuel T. Harris
1999-07-01  0:00 ` czgrr
1999-07-01  0:00   ` Ted Dennison
1999-07-02  0:00     ` czgrr
1999-07-02  0:00       ` Ted Dennison
1999-07-02  0:00 ` Robert Dewar
1999-07-02  0:00   ` Samuel T. Harris
1999-07-02  0:00     ` Robert Dewar
     [not found]       ` <7ltl2q$mog$1@nnrp1.deja.com>
1999-07-08  0:00         ` Michael F. Yoder
1999-07-09  0:00           ` Robert Dewar
1999-07-09  0:00             ` Michael F. Yoder
1999-07-14  0:00               ` Tucker Taft
1999-07-09  0:00             ` Dale Stanbrough
1999-07-12  0:00               ` Robert Dewar
1999-07-12  0:00                 ` Ted Dennison
1999-07-10  0:00             ` Simon Wright
1999-07-12  0:00               ` Robert Dewar
1999-07-09  0:00           ` Richard D Riehle
1999-07-09  0:00             ` Michael F. Yoder
1999-07-09  0:00             ` Marin David Condic
1999-07-08  0:00       ` R. Tim Coslet
1999-07-09  0:00         ` Robert Dewar
1999-07-09  0:00           ` tmoran
1999-07-02  0:00   ` Ted Dennison
1999-07-02  0:00     ` Stephen Leake
1999-07-02  0:00     ` Robert Dewar
     [not found]       ` <7ltus1$ah1@dfw-ixnews19.ix.netcom.com>
1999-07-13  0:00         ` Robert A Duff [this message]
1999-07-18  0:00           ` Richard D Riehle
1999-07-18  0:00             ` jerry
1999-07-19  0:00               ` Vladimir Olensky
1999-07-20  0:00               ` Richard D Riehle
1999-07-20  0:00                 ` Opaque Types (was Elimination of "use" clauses) David C. Hoos, Sr.
1999-07-20  0:00                 ` Elimination of "use" clauses jerry
1999-07-18  0:00             ` Dale Stanbrough
1999-07-20  0:00               ` David Kristola
1999-07-20  0:00               ` Richard D Riehle
1999-07-19  0:00                 ` Brian Rogoff
1999-07-20  0:00                   ` Robert Dewar
1999-07-20  0:00                     ` Brian Rogoff
1999-07-21  0:00                       ` Ted Dennison
1999-07-21  0:00                         ` Robert A Duff
1999-07-21  0:00                         ` Robert Dewar
1999-07-21  0:00                       ` Robert Dewar
1999-07-21  0:00                         ` Brian Rogoff
1999-07-22  0:00                           ` Robert Dewar
1999-07-22  0:00                             ` Brian Rogoff
1999-07-22  0:00                           ` Robert Dewar
1999-07-22  0:00                             ` Brian Rogoff
1999-07-21  0:00                     ` Robert A Duff
1999-07-21  0:00                       ` Michael F. Yoder
1999-07-21  0:00                         ` Robert A Duff
1999-07-23  0:00                 ` Tucker Taft
1999-08-03  0:00                   ` Richard D Riehle
1999-07-19  0:00             ` Ted Dennison
1999-07-19  0:00               ` Tucker Taft
1999-07-19  0:00                 ` Ted Dennison
1999-07-02  0:00     ` Ed Falis
1999-07-02  0:00   ` Ed Falis
1999-07-03  0:00     ` Joe Wisniewski
1999-07-03  0:00       ` Ed Falis
1999-07-03  0:00       ` Keith Thompson
1999-07-13  0:00     ` Peter Amey
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox