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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ab3fadb7cac7363c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.93.MISMATCH!xlned.com!feeder7.xlned.com!news2.euro.net!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: using `use' : what is the best practice ? Date: Tue, 07 Jun 2011 16:59:05 +0100 Organization: A noiseless patient Spider Message-ID: References: <57e75a35-058c-4172-9a3d-e11e7c5f7697@l2g2000prg.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="32616"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9Jmuv/xj0kgn86sv2fjAiPLXCk9ZyChg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:7vrB5KVP2IZWYV9bOgZ1ZaMjp4w= sha1:VnzJY0oZLHk1NM/fbFBiYY5k7vo= Xref: g2news2.google.com comp.lang.ada:20647 Date: 2011-06-07T16:59:05+01:00 List-Id: milouz writes: > Hi guys, > Maybe a not so anecdotic question : when using the 'use' clause ? > > My first thought is that using 'use' is not good because it masks the > package tree. 100% agree. Well, actually more like 90%! I have no problem writing with Ada.Text_IO; use Ada.Text_IO; (but, I'd most often be using Text_IO for debug trace output, not in operational code). And some packages (Ada.Strings.Unbounded) are designed to be "use"d. AdaCore tend to use package renaming, eg package SSE renames System.Storage_Elements; > For example, if I have 2 packages with procedures sharing the same > name, example `P1.Foo' and `P2.Foo', my code won't be very readable if > I only write the short name (`Foo') : > > with P1; use P1; > with P2; use P2; > > procedure Main is > My_Val : Integer; > begin > Foo(My_Val); -- P1 or P2 ? And would not even compile, if both packages contained a procedure Foo. > But always avoiding 'use' give some rather obfuscated code, especially > when using some specific arithmetic operator. For example, playing > with Address arithmetic without 'use' : > System.Storage_Elements."+"(System.Storage_Elements.Storage_Offset(N), > A); See "use type", designed for exactly this purpose. http://www.adaic.org/resources/add_content/standards/05rm/html/RM-8-4.html#I3407 Although you can "use type" in the context clauses (the "with"s) I much prefer to put them as close as possible to the actual use: eg, in the declarative region of a subprogram. Of course, if all the subprograms in a package need to "use type", move the "use type" to package scope.