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,WEIRD_PORT 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: g2news1.google.com!news3.google.com!feeder.news-service.com!goblin2!goblin.stu.neva.ru!fi.sn.net!newsfeed1.tdcnet.fi!news.song.fi!not-for-mail From: Anders Wirzenius Newsgroups: comp.lang.ada Subject: Re: using `use' : what is the best practice ? References: <57e75a35-058c-4172-9a3d-e11e7c5f7697@l2g2000prg.googlegroups.com> Date: Tue, 07 Jun 2011 22:32:54 +0300 Message-ID: <87hb818mjd.fsf@cawu.ok8> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:MyQeqBEhm6V07j7OPXBdBOt1XF4= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Netikka NNTP-Posting-Host: 81.209.10.42 X-Trace: 1307477281 news.netikka.fi 2836 81.209.10.42:46875 X-Complaints-To: abuse@netikka.fi Xref: g2news1.google.com comp.lang.ada:19688 Date: 2011-06-07T22:32:54+03:00 List-Id: milouz writes: > Hi guys, > Sorry with my annoying questions, but it's not easy to program in Ada > after 20 years programming in asm / C ;-) > > 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. > 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 ? > ... > > But always avoiding 'use' give some rather obfuscated code, especially > when using some specific arithmetic operator. For example, playing > with Address arithmetic without 'use' : > > with System; > with System.Storage_Elements; > > procedure Main is > A : System.Address; > N : Integer; > begin > A := System.Storage_Elements.To_Address(16#10000#); > N := 4; > > System.Storage_Elements."+"(System.Storage_Elements.Storage_Offset(N), > A); > end Main; > > The same code with 'use' is more readable : > > with System; use System; > with System.Storage_Elements; use System.Storage_Elements; > > procedure Main is > A : Address; > N : Integer; > begin > A := To_Address(16#10000#); > N := 4; > A := A + Storage_Offset(N); > end Main; > > As I'm very new, I'd like to have your opinion about the way to use > 'use'. > > > You may restrict the context of a 'use': with Text_IO; procedure Bl is A : String := "aaa"; begin Text_IO.Put_Line (A); declare use Text_IO; A : character := 'b'; begin Put (A); end; Put_Line (A); end; Try to compile the code. The error message (Gnat) will be: gnatmake bl.adb gcc-4.4 -c bl.adb bl.adb:12:04: "Put_Line" is not visible bl.adb:12:04: non-visible declaration at a-textio.ads:263 bl.adb:12:04: non-visible declaration at a-textio.ads:259 gnatmake: "bl.adb" compilation error -- Anders