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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6cb2525ffbfe23ce X-Google-Attributes: gid103376,public From: Corey Minyard Subject: Re: Why both "with" and "use"? Date: 1999/02/13 Message-ID: #1/1 X-Deja-AN: 444049922 Sender: minyard@wf-rch.cirr.com References: <36C5B28C.F32C43A4@jps.net> Organization: Wonderforce Research Reply-To: minyard@acm.org Newsgroups: comp.lang.ada Date: 1999-02-13T00:00:00+00:00 List-Id: Mike Silva 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