comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: using `use' : what is the best practice ?
Date: Tue, 07 Jun 2011 16:59:05 +0100
Date: 2011-06-07T16:59:05+01:00	[thread overview]
Message-ID: <m262oh63au.fsf@pushface.org> (raw)
In-Reply-To: 57e75a35-058c-4172-9a3d-e11e7c5f7697@l2g2000prg.googlegroups.com

milouz <a.michelizza@gmail.com> 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.



  reply	other threads:[~2011-06-07 15:59 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-07 15:32 using `use' : what is the best practice ? milouz
2011-06-07 15:59 ` Simon Wright [this message]
2011-06-07 16:22 ` Dmitry A. Kazakov
2011-06-07 16:59   ` Simon Wright
2011-06-07 17:25     ` Dmitry A. Kazakov
2011-06-07 17:29       ` Simon Wright
2011-06-07 19:38         ` Dmitry A. Kazakov
2011-06-11 14:11           ` Yannick Duchêne (Hibou57)
2011-06-08  9:07       ` Paul Colin Gloster
2011-06-08 11:20         ` stefan-lucks
2011-06-08 16:45           ` Vinzent Hoefler
2011-06-11 14:05       ` Yannick Duchêne (Hibou57)
2011-06-07 17:33 ` Pascal Obry
2011-06-08  2:42   ` Randy Brukardt
2011-06-12  5:09   ` Yannick Duchêne (Hibou57)
2011-06-07 18:51 ` Jeffrey Carter
2011-06-08  0:04   ` Peter C. Chapin
2011-06-07 19:32 ` Anders Wirzenius
2011-06-07 23:38 ` Shark8
2011-06-12  5:19   ` Yannick Duchêne (Hibou57)
2011-06-12  7:55   ` Stephen Leake
2011-06-08  4:25 ` Jerry
2011-06-08  9:31   ` milouz
2011-06-08 17:17     ` Ludovic Brenta
2011-06-08 18:43     ` Jeffrey Carter
2011-06-09 10:40       ` Address arithmetic alternatives milouz
2011-06-09 11:25         ` Georg Bauhaus
2011-06-09 18:53         ` Jeffrey Carter
2011-06-08 19:22     ` using `use' : what is the best practice ? Pascal Obry
2011-06-09  1:17     ` Shark8
2011-06-09 10:44       ` milouz
2011-06-08  6:06 ` stefan-lucks
2011-06-15  2:25 ` Adrian Hoe
replies disabled

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