comp.lang.ada
 help / color / mirror / Atom feed
From: Corey Minyard <minyard@acm.org>
Subject: Re: Why both "with" and "use"?
Date: 1999/02/13
Date: 1999-02-13T00:00:00+00:00	[thread overview]
Message-ID: <m2socaxfjw.fsf@wf-rch.cirr.com> (raw)
In-Reply-To: 36C5B28C.F32C43A4@jps.net

Mike Silva <mjsilva@jps.net> writes:

> Somebody on comp.lang.fortran noticed these two lines in an Ada snippet
> and questioned why both lines were needed (vs. only USE in Fortran).
> 
> >with Ada.Numerics.Elementary_Functions;
> >use  Ada.Numerics.Elementary_Functions;
> 
> I, with two whole weeks of Ada experience, understand the difference
> (sorta) but don't really understand the rationale.  Would anybody care
> to explain the why of it?  Thanks.
> 
> Mike

Although I'm not in the league of others in this group, I'll give my
opinion.

The with clause allows things in the "withed" to be used explicitly
with their name with the package preceding, such as

  X := Ada.Numerics.Elementary_Functions.Sqrt(10.0);

The use clause generally (but not always) causes things to be
available with the name only, such as

  X := Sqrt(10.0);

If there were another function named Sqrt in another "used" package that
took the same type argument(s), the whole name would still be necessary
so the compiler could tell which one to use.

I hardly ever use "use" clauses any more, just "use type" clauses when
necessary.  When you develop a large system, it becomes difficult to
find where something is declared.  In this particular example, I would
probably use the "use" clause because the source would be obvious to
any good Ada programmer.  But in most cases, being able to know the
package the item is declared in is quite useful.  I've look at far too
many C programs where I spend most of my time finding where functions
are declared.  A well written Ada program won't have nearly as big a
problem with that.

It can make the code messy to have huge names, so I'll sometimes use
package renaming to shorten the names and still retain clarity.  But
it can be a balancing act sometimes.  The whole thing is a balancing

Hope this helps.

-- 
Corey Minyard                   Internet:  minyard@acm.org
  Work: minyard@nortelnetworks.com  UUCP:  minyard@wf-rch.cirr.com




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

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-13  0:00 Why both "with" and "use"? Mike Silva
1999-02-13  0:00 ` Corey Minyard [this message]
1999-02-13  0:00   ` Matthew Heaney
1999-02-13  0:00     ` Tom Moran
1999-02-14  0:00       ` Matthew Heaney
1999-02-13  0:00     ` bill
1999-02-14  0:00       ` dewar
1999-02-14  0:00       ` Matthew Heaney
1999-02-14  0:00       ` dewar
1999-02-16  0:00     ` Samuel Mize
1999-02-17  0:00       ` Matthew Heaney
1999-02-17  0:00       ` Jean-Pierre Rosen
1999-02-18  0:00         ` dennison
1999-02-18  0:00           ` robert_dewar
1999-02-19  0:00             ` bourguet
1999-02-19  0:00               ` robert_dewar
1999-02-19  0:00             ` Robert I. Eachus
1999-02-19  0:00               ` robert_dewar
1999-02-23  0:00                 ` Robert I. Eachus
1999-02-19  0:00               ` Brian Hanson
1999-02-19  0:00                 ` robert_dewar
1999-02-19  0:00             ` dennison
1999-02-19  0:00           ` Matthew Heaney
1999-02-19  0:00             ` dennison
1999-02-19  0:00               ` robert_dewar
1999-02-19  0:00                 ` Ada multiple string personalities. why so many? mike
1999-02-19  0:00                   ` robert_dewar
1999-02-19  0:00                   ` Tom Moran
1999-02-19  0:00                     ` Mike Silva
1999-02-22  0:00                       ` Brian Hanson
1999-02-19  0:00                 ` Why both "with" and "use"? dennison
1999-02-19  0:00                   ` robert_dewar
1999-02-18  0:00         ` robert_dewar
1999-02-18  0:00           ` Jean-Pierre Rosen
1999-02-18  0:00             ` robert_dewar
1999-02-19  0:00               ` Jean-Pierre Rosen
1999-02-17  0:00       ` dennison
1999-02-17  0:00         ` Samuel Mize
1999-02-17  0:00         ` Nick Roberts
1999-02-17  0:00       ` Jean-Pierre Rosen
1999-02-13  0:00   ` mike
1999-02-13  0:00 ` Pat Rogers
1999-02-13  0:00   ` bill
1999-02-13  0:00     ` Matthew Heaney
1999-02-13  0:00     ` Pat Rogers
1999-02-13  0:00       ` Matthew Heaney
1999-02-13  0:00         ` bill
1999-02-14  0:00         ` Pat Rogers
1999-02-14  0:00           ` Bob Collins
1999-02-14  0:00             ` Pat Rogers
1999-02-16  0:00         ` Samuel Mize
1999-02-15  0:00     ` Jean-Pierre Rosen
1999-02-15  0:00       ` Ed Falis
1999-02-16  0:00         ` Jean-Pierre Rosen
1999-02-15  0:00 ` Jean-Pierre Rosen
replies disabled

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