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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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 Path: g2news2.google.com!postnews.google.com!d19g2000prh.googlegroups.com!not-for-mail From: Adrian Hoe Newsgroups: comp.lang.ada Subject: Re: using `use' : what is the best practice ? Date: Tue, 14 Jun 2011 19:25:03 -0700 (PDT) Organization: http://groups.google.com Message-ID: <21a80b6b-00c2-4cd0-8561-c2b853f7722e@d19g2000prh.googlegroups.com> References: <57e75a35-058c-4172-9a3d-e11e7c5f7697@l2g2000prg.googlegroups.com> NNTP-Posting-Host: 110.159.15.203 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1308104740 14428 127.0.0.1 (15 Jun 2011 02:25:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 15 Jun 2011 02:25:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d19g2000prh.googlegroups.com; posting-host=110.159.15.203; posting-account=coq9PAkAAAB2Xx46RZLFJw5dY9DVXW4- User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUARLECNK X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:20806 Date: 2011-06-14T19:25:03-07:00 List-Id: On Jun 7, 11:32=A0pm, milouz wrote: > 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') : > > =A0 =A0with P1; use P1; > =A0 =A0with P2; use P2; > > =A0 =A0procedure Main is > =A0 =A0 =A0 My_Val : Integer; > =A0 =A0begin > =A0 =A0 =A0 Foo(My_Val); =A0-- P1 or P2 ? > =A0 =A0... I "use" packages when I need to "use" its type and many calls to subprograms in it to avoid lengthy code. You can always explicitly write: P1.Foo ( My_Val ); P2.F00 ( My_Val ); The beauty of Ada is that it is not only an implementation language, it is also a documentation language. > But always avoiding 'use' give some rather obfuscated code, especially > when using some specific arithmetic operator. For example, playing > with Address arithmetic without 'use' : > > =A0 =A0with System; > =A0 =A0with System.Storage_Elements; > > =A0 =A0procedure Main is > =A0 =A0 =A0 A : System.Address; > =A0 =A0 =A0 N : Integer; > =A0 =A0begin > =A0 =A0 =A0 A :=3D System.Storage_Elements.To_Address(16#10000#); > =A0 =A0 =A0 N :=3D 4; > > System.Storage_Elements."+"(System.Storage_Elements.Storage_Offset(N), > A); > =A0 =A0end Main; > > The same code with 'use' is more readable : > > =A0 =A0with System; use System; > =A0 =A0with System.Storage_Elements; use System.Storage_Elements; > > =A0 =A0procedure Main is > =A0 =A0 =A0 A : Address; > =A0 =A0 =A0 N : Integer; > =A0 =A0begin > =A0 =A0 =A0 A :=3D To_Address(16#10000#); > =A0 =A0 =A0 N :=3D 4; > =A0 =A0 =A0 A :=3D A + Storage_Offset(N); > =A0 =A0end Main; with System; use System; with System.Storage_Elements; use System.Storage_Elements; procedure Main is A : System.Address; ... This will be more readable though, IMO. -- Adrian Hoe http://adrianhoe.com/adrianhoe