comp.lang.ada
 help / color / mirror / Atom feed
* using `use' : what is the best practice ?
@ 2011-06-07 15:32 milouz
  2011-06-07 15:59 ` Simon Wright
                   ` (8 more replies)
  0 siblings, 9 replies; 33+ messages in thread
From: milouz @ 2011-06-07 15:32 UTC (permalink / raw)


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'.






^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
@ 2011-06-07 15:59 ` Simon Wright
  2011-06-07 16:22 ` Dmitry A. Kazakov
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 33+ messages in thread
From: Simon Wright @ 2011-06-07 15:59 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
  2011-06-07 15:59 ` Simon Wright
@ 2011-06-07 16:22 ` Dmitry A. Kazakov
  2011-06-07 16:59   ` Simon Wright
  2011-06-07 17:33 ` Pascal Obry
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 33+ messages in thread
From: Dmitry A. Kazakov @ 2011-06-07 16:22 UTC (permalink / raw)


On Tue, 7 Jun 2011 08:32:25 -0700 (PDT), milouz wrote:

> Maybe a not so anecdotic question : when using the 'use' clause ?

Always, and packages has to be designed to be "use-friendly."

> 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 ?
>    ...

Why do you want to know this?

The program must be understandable without this knowledge. Surely if you
choose names like "Foo" that won't happen. What kind of useful information
"P1.Foo" carries compared to "Foo"?

Furthermore location of Foo can be viewed as an implementation detail.
Especially when Foo is a primitive operation with many bodies scattered all
around. In general, the idea of fully qualified names is incompatible with
generic programming, i.e. when some operations are defined on a class of
types with different bodies for different members of the class.

P.S. All Ada users are subdivided into use-haters and with-haters. The
former are in majority.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 16:22 ` Dmitry A. Kazakov
@ 2011-06-07 16:59   ` Simon Wright
  2011-06-07 17:25     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 33+ messages in thread
From: Simon Wright @ 2011-06-07 16:59 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> P.S. All Ada users are subdivided into use-haters and with-haters. The
> former are in majority.

use-haters and use-lovers? Hating "with" would match pretty well with
hating Ada, I'd have thought!



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 16:59   ` Simon Wright
@ 2011-06-07 17:25     ` Dmitry A. Kazakov
  2011-06-07 17:29       ` Simon Wright
                         ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Dmitry A. Kazakov @ 2011-06-07 17:25 UTC (permalink / raw)


On Tue, 07 Jun 2011 17:59:08 +0100, Simon Wright wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> P.S. All Ada users are subdivided into use-haters and with-haters. The
>> former are in majority.
> 
> use-haters and use-lovers? Hating "with" would match pretty well with
> hating Ada, I'd have thought!

In

   with P; use P;

the "with P" is meaningless here.

"With" does not carry any useful information for the reader. You have to
manage sets of "with" as you develop your packages. I bet even most
stubborn use-haters do not take the idea of "with" seriously. Because
otherwise they would have to mention *all* implicitly or explicitly
referenced packages in "with" clauses. This mammoth task would go to waste.
Because the information to brings is null, and interesting only to the
compiler-linker. And if you are in favor of dotted names longer than the
source line, why would you need an additional "with" if the source is
already full of package names?

BTW, there is another dichotomy: child packages-haters vs. with-haters.
Package dependencies introduced by children-parent relation are more
evident and less arbitrary than ones by "with." The only problem is that
multiple parents are not allowed.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  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-08  9:07       ` Paul Colin Gloster
  2011-06-11 14:05       ` Yannick Duchêne (Hibou57)
  2 siblings, 1 reply; 33+ messages in thread
From: Simon Wright @ 2011-06-07 17:29 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> Because
> otherwise they would have to mention *all* implicitly or explicitly
> referenced packages in "with" clauses. This mammoth task would go to waste.

Perhaps that's why the language designers didn't go that way.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
  2011-06-07 15:59 ` Simon Wright
  2011-06-07 16:22 ` Dmitry A. Kazakov
@ 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
                   ` (5 subsequent siblings)
  8 siblings, 2 replies; 33+ messages in thread
From: Pascal Obry @ 2011-06-07 17:33 UTC (permalink / raw)
  To: milouz

Le 07/06/2011 17:32, milouz a �crit :
> But always avoiding 'use' give some rather obfuscated code, especially
> when using some specific arithmetic operator. For example, playing
> with Address arithmetic without 'use' :

I don't like use so when *I* design a package I prefer to take a 
convention where use is not necessary. But when you want to use an 
already built API you must often use it the way it has been designed to 
be used. Take for example Unbounded_String, nobody will avoid using use 
in this case... Look at this code:

    with Ada.Strings.Unbounded;
    procedure Whatever is
       S : Ada.Strings.Unbounded.Unbounded_String;
    begin
       Ada.Strings.Unbounded.Append (S, "toto");
    end Whatever;

Far better with:

    with Ada.Strings.Unbounded;
    procedure Whatever is
       use Ada.Strings.Unbounded;
       S : Unbounded_String;
    begin
       Append (S, "toto");
    end Whatever;

Because Ada.Strings.Unbounded (and all Ada runtime packages) has been 
designed to be used with a use clause.

Now I do prefer:

    package Circle is
       type Object is...

And use it as:

    with Circle;

    O : Circle.Object;

To

    package Circle is
       type Circle_Type is...

And use it as:

    with Circle; use Circle;

    O : Circle_Type;

But all styles are around...

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|    http://www.obry.net  -  http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
                   ` (2 preceding siblings ...)
  2011-06-07 17:33 ` Pascal Obry
@ 2011-06-07 18:51 ` Jeffrey Carter
  2011-06-08  0:04   ` Peter C. Chapin
  2011-06-07 19:32 ` Anders Wirzenius
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 33+ messages in thread
From: Jeffrey Carter @ 2011-06-07 18:51 UTC (permalink / raw)


On 06/07/2011 08:32 AM, milouz wrote:
>
> Maybe a not so anecdotic question : when using the 'use' clause ?

This is something of a religious topic; people have strong opinions one way or 
the other. "Best" is difficult to define objectively.

However, it's interesting to note that use clauses are not allowed in Spark. If 
correctness of your SW is important enough to use Spark, you won't have use clauses.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
                   ` (3 preceding siblings ...)
  2011-06-07 18:51 ` Jeffrey Carter
@ 2011-06-07 19:32 ` Anders Wirzenius
  2011-06-07 23:38 ` Shark8
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 33+ messages in thread
From: Anders Wirzenius @ 2011-06-07 19:32 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 17:29       ` Simon Wright
@ 2011-06-07 19:38         ` Dmitry A. Kazakov
  2011-06-11 14:11           ` Yannick Duchêne (Hibou57)
  0 siblings, 1 reply; 33+ messages in thread
From: Dmitry A. Kazakov @ 2011-06-07 19:38 UTC (permalink / raw)


On Tue, 07 Jun 2011 18:29:48 +0100, Simon Wright wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> Because
>> otherwise they would have to mention *all* implicitly or explicitly
>> referenced packages in "with" clauses. This mammoth task would go to waste.
> 
> Perhaps that's why the language designers didn't go that way.

It was different in n 80s, projects were much smaller. There were almost no
reusable components. You could really gasp all relationships between your
packages. The structure of packages was very rigid, designed up front.

In these days this is just unrealistic, so the coding style must adapt and
the language should provide some support. I would prefer stricter rules on
declarations hiding each other (requiring explicit resolution of all
conflicts) [*]. I definitely want a stronger than "use", transitive clause
to incorporate the declaration scope of a package into the scope of another
package. I would like to have multiple parents too.

-----------------------
* When people play this card against MI, they forget that packages allow
exactly same. And if fully qualified names were a solution for packages,
why it could not be for MI as well?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
                   ` (4 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  8 siblings, 2 replies; 33+ messages in thread
From: Shark8 @ 2011-06-07 23:38 UTC (permalink / raw)


On Jun 7, 10:32 am, milouz <a.micheli...@gmail.com> 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.

While this is true it can be handy for reducing prefix-clutter,
as could a rename. So, while you may be hesitant to use them on the
package, I find using them in declare-blocks and subprograms to be
quite readable and usable.

With
Ada.Text_IO;

Package Body Example is
 [...]
 Procedure Something_Interesting is
   Use Ada.Text_IO; -- We're debugging here.
 begin
   [...]
  Put_Line( "Debugging marker." );
   [...]
 end Something_interesting;
End Example;

> 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;
[...]
> As I'm very new, I'd like to have your opinion about the way to use
> 'use'.

Ah, I like to use the comma-separated forms of use/with; this can be
helpful if you wish to do a quick commenting out of a use or with to
pass to the compiler and see if you really need it at all.

EX:
With
Ada.Text_IO,
--Ada.Integer_IO, -- Am I even using Ada.Integer_IO?
--Ada.Tags,
--MY_PARSING_PACKAGE,
[...]
MY_CONSOLE_MANIPULATION_PACKAGE
;

Use
Ada.Text_IO,
--Ada.Tags,  -- Do I really need to USE tags?
MY_CONSOLE_MANIPULATION_PACKAGE;




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 18:51 ` Jeffrey Carter
@ 2011-06-08  0:04   ` Peter C. Chapin
  0 siblings, 0 replies; 33+ messages in thread
From: Peter C. Chapin @ 2011-06-08  0:04 UTC (permalink / raw)


On Tue, 07 Jun 2011 11:51:43 -0700, Jeffrey Carter wrote:

> However, it's interesting to note that use clauses are not allowed in
> Spark. If correctness of your SW is important enough to use Spark, you
> won't have use clauses.

It should be noted that SPARK does allow a (limited) form of 'use type' 
precisely so that operators can be made directly visible.

Peter




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 17:33 ` Pascal Obry
@ 2011-06-08  2:42   ` Randy Brukardt
  2011-06-12  5:09   ` Yannick Duchêne (Hibou57)
  1 sibling, 0 replies; 33+ messages in thread
From: Randy Brukardt @ 2011-06-08  2:42 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1929 bytes --]

"Pascal Obry" <pascal@obry.net> wrote in message 
news:4DEE60E9.2020408@obry.net...
> Le 07/06/2011 17:32, milouz a �crit :
...
> I don't like use so when *I* design a package I prefer to take a 
> convention where use is not necessary. But when you want to use an already 
> built API you must often use it the way it has been designed to be used. 
> Take for example Unbounded_String, nobody will avoid using use in this 
> case... Look at this code:
>
>    with Ada.Strings.Unbounded;
>    procedure Whatever is
>       S : Ada.Strings.Unbounded.Unbounded_String;
>    begin
>       Ada.Strings.Unbounded.Append (S, "toto");
>    end Whatever;

Looks good to me, it's what I would write.

> Far better with:
>
>    with Ada.Strings.Unbounded;
>    procedure Whatever is
>       use Ada.Strings.Unbounded;
>       S : Unbounded_String;
>    begin
>       Append (S, "toto");
>    end Whatever;

Maybe, if that is the entire package. But that's not usually the case, and 
typically the use of Unbounded_Strings is a very small fraction of the code. 
Moreover, if you also have fixed strings floating around (which I usually 
do), and some uses of Ada.Strings.Fixed as well (which also are pretty 
likely), use clauses are simply not going to work. The typical expression 
cannot be understood by the compiler, and trying to figure out why will be 
impossible.

I sometimes rename the horribly named "To_Unbounded_String" to "+" (this 
operation needs to be short), and occasionally will use a "use clause" in a 
subprogram scope. But that's about it.

> Because Ada.Strings.Unbounded (and all Ada runtime packages) has been 
> designed to be used with a use clause.

Right, and it is unfortunate.

With Claw, we tried to split the difference; we used short subprogram names 
and longer type names. The "Object" trick was too weird for me at the time 
(and I still don't like it much).

                             Randy.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
                   ` (5 preceding siblings ...)
  2011-06-07 23:38 ` Shark8
@ 2011-06-08  4:25 ` Jerry
  2011-06-08  9:31   ` milouz
  2011-06-08  6:06 ` stefan-lucks
  2011-06-15  2:25 ` Adrian Hoe
  8 siblings, 1 reply; 33+ messages in thread
From: Jerry @ 2011-06-08  4:25 UTC (permalink / raw)


On Jun 7, 8:32 am, milouz <a.micheli...@gmail.com> wrote:
> Hi guys,
> Sorry with my annoying questions, but it's not easy to program in Ada
> after 20 years programming in asm / C ;-)

<snip>

> For example, playing
> with Address arithmetic

<snip>

Your questions are not annoying.

This is off-topic, but you appear to be perhaps new to Ada. May I ask
why you are looking into address arithmetic? Maybe this is a asm/C
habit that you are transferring to Ada. I'm not an Ada expert but
there may well be other ways to accomplish what you want without using
address arithmetic which I believe is generally frowned upon except in
certain circumstances. You might find record-representation clauses to
be useful.

Jerry



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
                   ` (6 preceding siblings ...)
  2011-06-08  4:25 ` Jerry
@ 2011-06-08  6:06 ` stefan-lucks
  2011-06-15  2:25 ` Adrian Hoe
  8 siblings, 0 replies; 33+ messages in thread
From: stefan-lucks @ 2011-06-08  6:06 UTC (permalink / raw)


On Tue, 7 Jun 2011, milouz wrote:

> Maybe a not so anecdotic question : when using the 'use' clause ?

I am sure you will get a lot of different answers about this. 

Note that your example below is using "use" in the "context clause" (i.e., 
where the "with" is). 

>    with P1; use P1;
>    with P2; use P2;
> 
>    procedure Main is
>       My_Val : Integer;
>    begin
>       Foo(My_Val);  -- P1 or P2 ?
>    ...

Try out what your program does! If P1 defines 
  procedure Foo(I: Integer); 
and P2 defines only, say, 
  Procedure Foo(S: String);
then the Ada compiler will know that you are calling P1.Foo. You are 
allowed to write P1.Foo(My_Val) to improve the readability of your code. 

On the other hand, if P2 also defines 
  procedure Foo(I: Integer);
you *must* either write P1.Foo(My_Val) or P2.Foo(My_Val). The compiler 
will not try to "guess" which Foo you wanted to call, it will just give 
you the syntax error you deserve. 

> But always avoiding 'use' give some rather obfuscated code, especially
> when using some specific arithmetic operator. For example, playing
> with Address arithmetic without 'use' :

There are alternatives to the use in the syntax clause:
  -> use type;
  -> a renames clause 
  -> a local use 

>    with System;
>    with System.Storage_Elements;
> 
>    procedure Main is
>       A : System.Address;
>       N : Integer;

        use System.Storage_Elements;
        -- locally in any scope -- not very local if in the main procedure
 
        use type System.Address;
        -- alternative: use type

        package SSE renames System.Storage_Elements;
        -- alternative: renames

>    begin
>       A := System.Storage_Elements.To_Address(16#10000#);

        -- A := To_Address(...); -- for local use (or in context clause)
                                 -- but not for use type!

        -- A := SSE.To_Address(...); -- for renames

>       N := 4;
>  
> A := System.Storage_Elements."+"(System.Storage_Elements.Storage_Offset(N), A);

  -- A := SSE."+"(SSE.Storage_Offset(N), A); -- for renames

  -- A := Storage_Offset(N)+ A; -- for local use, context-clause use 
                                -- and use type

>    end Main;
> 
> As I'm very new, I'd like to have your opinion about the way to use
> 'use'.

Always consider the alternatives to the context-clause use!


-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 17:25     ` Dmitry A. Kazakov
  2011-06-07 17:29       ` Simon Wright
@ 2011-06-08  9:07       ` Paul Colin Gloster
  2011-06-08 11:20         ` stefan-lucks
  2011-06-11 14:05       ` Yannick Duchêne (Hibou57)
  2 siblings, 1 reply; 33+ messages in thread
From: Paul Colin Gloster @ 2011-06-08  9:07 UTC (permalink / raw)


Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> sent on June 7th, 2011:
|------------------------------------------------------------------------|
|"[..]                                                                   |
|                                                                        |
|In                                                                      |
|                                                                        |
|   with P; use P;                                                       |
|                                                                        |
|the "with P" is meaningless here.                                       |
|                                                                        |
|"With" does not carry any useful information for the reader. You have to|
|manage sets of "with" as you develop your packages. [..]                |
|[..]                                                                    |
|                                                                        |
|[..]"                                                                   |
|------------------------------------------------------------------------|

Agreed. VHDL does not need this redundancy.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-08  4:25 ` Jerry
@ 2011-06-08  9:31   ` milouz
  2011-06-08 17:17     ` Ludovic Brenta
                       ` (3 more replies)
  0 siblings, 4 replies; 33+ messages in thread
From: milouz @ 2011-06-08  9:31 UTC (permalink / raw)



> This is off-topic, but you appear to be perhaps new to Ada. May I ask
> why you are looking into address arithmetic? Maybe this is a asm/C
> habit that you are transferring to Ada.

Yes, as I'm new to Ada, I still have a lot of things to learn /
understand. I'm a kernel developer, and my way to learn Ada is to
write some drivers and very low-level stuffs. That's why I need to
play with address arithmetic.

- Arnauld



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-08  9:07       ` Paul Colin Gloster
@ 2011-06-08 11:20         ` stefan-lucks
  2011-06-08 16:45           ` Vinzent Hoefler
  0 siblings, 1 reply; 33+ messages in thread
From: stefan-lucks @ 2011-06-08 11:20 UTC (permalink / raw)


> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> sent on June 7th, 2011:
> |------------------------------------------------------------------------|
> |"[..]                                                                   |
> |                                                                        |
> |In                                                                      |
> |                                                                        |
> |   with P; use P;                                                       |
> |                                                                        |
> |the "with P" is meaningless here.                                       |
> |                                                                        |
> |"With" does not carry any useful information for the reader. You have to|
> |manage sets of "with" as you develop your packages. [..]                |
> |[..]                                                                    |
> |                                                                        |
> |[..]"                                                                   |
> |------------------------------------------------------------------------|
> 
> Agreed. VHDL does not need this redundancy.

Do you mean, in VHDL you can write "use P;" without "with P"? (Or what 
kind of Syntax VHDL uses for Ada's "with Name" and "use Name" ...)

Or do you mean you can write "P.Some_Procedure(...)" or "P.Some_Type" 
without any "with" or "use" before? The compiler can certainly search for 
package P in such a case just as if you wrote "with P" at the beginning of 
your compilation usage, the explicit "with P" is for the human reader.


-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-08 11:20         ` stefan-lucks
@ 2011-06-08 16:45           ` Vinzent Hoefler
  0 siblings, 0 replies; 33+ messages in thread
From: Vinzent Hoefler @ 2011-06-08 16:45 UTC (permalink / raw)


Stefan Lucks wrote:

[with/use]
>> Agreed. VHDL does not need this redundancy.
>
> Do you mean, in VHDL you can write "use P;" without "with P"? (Or what
> kind of Syntax VHDL uses for Ada's "with Name" and "use Name" ...)

It's a couple of years already, so I may not remember correctly, but AFAIR you can:

library IEEE;  use IEEE.Std_Logic_1164;
                use IEEE.Std_Logic_Arith;

And thus, directly use child packages.

> Or do you mean you can write "P.Some_Procedure(...)" or "P.Some_Type"
> without any "with" or "use" before?

No.


Vinzent.

-- 
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-08  9:31   ` milouz
@ 2011-06-08 17:17     ` Ludovic Brenta
  2011-06-08 18:43     ` Jeffrey Carter
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 33+ messages in thread
From: Ludovic Brenta @ 2011-06-08 17:17 UTC (permalink / raw)


milouz writes on comp.lang.ada:
>> This is off-topic, but you appear to be perhaps new to Ada. May I ask
>> why you are looking into address arithmetic? Maybe this is a asm/C
>> habit that you are transferring to Ada.
>
> Yes, as I'm new to Ada, I still have a lot of things to learn /
> understand. I'm a kernel developer, and my way to learn Ada is to
> write some drivers and very low-level stuffs. That's why I need to
> play with address arithmetic.

Are you aware of Lovelace?  It could use your help and you can learn a
lot by studying the existing sources.  It is small enough for one person
to understand.  The last thing I heard was that it could boot in qemu
and had virtual memory management and exception handling.

There used to be a web site, http://lovelace.fr, but is is down ATM.
The sources are still available on Ada-France's monotone server:

http://www.ada-france.org:8081/branch/changes/org.os-lovelace

-- 
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  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-08 19:22     ` using `use' : what is the best practice ? Pascal Obry
  2011-06-09  1:17     ` Shark8
  3 siblings, 1 reply; 33+ messages in thread
From: Jeffrey Carter @ 2011-06-08 18:43 UTC (permalink / raw)


On 06/08/2011 02:31 AM, milouz wrote:
>
> Yes, as I'm new to Ada, I still have a lot of things to learn /
> understand. I'm a kernel developer, and my way to learn Ada is to
> write some drivers and very low-level stuffs. That's why I need to
> play with address arithmetic.

More correctly, you *think* you need to play with address arithmetic. You may be 
right, but address arithmetic is needed extremely rarely in Ada. Ada has 
alternatives to most address arithmetic in C.

However, this has nothing to do with use clauses.

-- 
Jeff Carter
"Apart from the sanitation, the medicine, education, wine,
public order, irrigation, roads, the fresh water system,
and public health, what have the Romans ever done for us?"
Monty Python's Life of Brian
80



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-08  9:31   ` milouz
  2011-06-08 17:17     ` Ludovic Brenta
  2011-06-08 18:43     ` Jeffrey Carter
@ 2011-06-08 19:22     ` Pascal Obry
  2011-06-09  1:17     ` Shark8
  3 siblings, 0 replies; 33+ messages in thread
From: Pascal Obry @ 2011-06-08 19:22 UTC (permalink / raw)


Le 08/06/2011 11:31, milouz a �crit :
> Yes, as I'm new to Ada, I still have a lot of things to learn /
> understand. I'm a kernel developer, and my way to learn Ada is to
> write some drivers and very low-level stuffs. That's why I need to
> play with address arithmetic.

Not sure what you are trying to do but maybe Interfaces.C.Pointers would 
fit your needs.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|    http://www.obry.net  -  http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-08  9:31   ` milouz
                       ` (2 preceding siblings ...)
  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
  3 siblings, 1 reply; 33+ messages in thread
From: Shark8 @ 2011-06-09  1:17 UTC (permalink / raw)


On Jun 8, 4:31 am, milouz <a.micheli...@gmail.com> wrote:
> > This is off-topic, but you appear to be perhaps new to Ada. May I ask
> > why you are looking into address arithmetic? Maybe this is a asm/C
> > habit that you are transferring to Ada.
>
> Yes, as I'm new to Ada, I still have a lot of things to learn /
> understand. I'm a kernel developer, and my way to learn Ada is to
> write some drivers and very low-level stuffs. That's why I need to
> play with address arithmetic.
>
> - Arnauld

I'm quite interested in OS development; and so I'd like to ask you [a
kernel developer] what is the best place to start (ground-up) on a
kernel?



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Address arithmetic alternatives
  2011-06-08 18:43     ` Jeffrey Carter
@ 2011-06-09 10:40       ` milouz
  2011-06-09 11:25         ` Georg Bauhaus
  2011-06-09 18:53         ` Jeffrey Carter
  0 siblings, 2 replies; 33+ messages in thread
From: milouz @ 2011-06-09 10:40 UTC (permalink / raw)



> More correctly, you *think* you need to play with address arithmetic. You may be
> right, but address arithmetic is needed extremely rarely in Ada. Ada has
> alternatives to most address arithmetic in C.

You're probably right. But what are those alternatives ?

- Arnauld



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-09  1:17     ` Shark8
@ 2011-06-09 10:44       ` milouz
  0 siblings, 0 replies; 33+ messages in thread
From: milouz @ 2011-06-09 10:44 UTC (permalink / raw)



> I'm quite interested in OS development; and so I'd like to ask you [a
> kernel developer] what is the best place to start (ground-up) on a
> kernel?

Replied by email.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Address arithmetic alternatives
  2011-06-09 10:40       ` Address arithmetic alternatives milouz
@ 2011-06-09 11:25         ` Georg Bauhaus
  2011-06-09 18:53         ` Jeffrey Carter
  1 sibling, 0 replies; 33+ messages in thread
From: Georg Bauhaus @ 2011-06-09 11:25 UTC (permalink / raw)


On 09.06.11 12:40, milouz wrote:
> 
>> More correctly, you *think* you need to play with address arithmetic. You may be
>> right, but address arithmetic is needed extremely rarely in Ada. Ada has
>> alternatives to most address arithmetic in C.
> 
> You're probably right. But what are those alternatives ?

I'd think array indexing (including ptrdiff_t stuff) is
a prominent example:

while (*s++) {
   ...
}

for K in S'Range loop
   ...
end loop;


Another is a C functions that reads two pointer, one a start
pointer and the other an offset pointer.

typedef ... t;

t* foo(const t* source, t* offset) { ...

In Ada, giving some more information about pointed to array
and the pointers via index ranges:

type T is ...;
type Indexing is range 0 .. Some_Maximum;
subtype Position is Indexing range 16#100# .. 16#1FF#;
subtype Distance is indexing
  range 0 .. Position'Last - Position'First;

type Array_of_T is array ( Position range <> ) of T;

function foo (Source : Array_of_T; Offset: Distance)
  return Distance;

(This doesn't mean that in C one couldn't write s[d], d++ or
that in Ada one couldn't use pointers with array components.
In fact, Ada.Containers features cursors. There is just much
expressive information in typed, constrained index values.
Depending on how much type information there is at compile
time, the compiler will reject a program if it can thus detect
a bounds violation (value not in type).)



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Address arithmetic alternatives
  2011-06-09 10:40       ` Address arithmetic alternatives milouz
  2011-06-09 11:25         ` Georg Bauhaus
@ 2011-06-09 18:53         ` Jeffrey Carter
  1 sibling, 0 replies; 33+ messages in thread
From: Jeffrey Carter @ 2011-06-09 18:53 UTC (permalink / raw)


On 06/09/2011 03:40 AM, milouz wrote:
>
>> More correctly, you *think* you need to play with address arithmetic. You may be
>> right, but address arithmetic is needed extremely rarely in Ada. Ada has
>> alternatives to most address arithmetic in C.
>
> You're probably right. But what are those alternatives ?

That depends on what you're trying to do. Probably the most common is (I 
apologize if my C is wrong)

p = a;
while (*p++) {
    /* do something with *p */
}

(which is wrong any since "a" may not contain a zero, and you go off accessing 
memory you shouldn't. This kind of thing is why C coders are creating yet more 
buffer-overflow vulnerabilities even as I type)

In Ada, one uses indexing:

for I in A'range loop
    -- Do something with A (I).
end loop;

-- 
Jeff Carter
"I was hobbling along, minding my own business, all of a
sudden, up he comes, cures me! One minute I'm a leper with
a trade, next minute my livelihood's gone! Not so much as a
'by your leave!' You're cured, mate. Bloody do-gooder!"
Monty Python's Life of Brian
76



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 17:25     ` Dmitry A. Kazakov
  2011-06-07 17:29       ` Simon Wright
  2011-06-08  9:07       ` Paul Colin Gloster
@ 2011-06-11 14:05       ` Yannick Duchêne (Hibou57)
  2 siblings, 0 replies; 33+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-06-11 14:05 UTC (permalink / raw)


Le Tue, 07 Jun 2011 19:25:29 +0200, Dmitry A. Kazakov  
<mailbox@dmitry-kazakov.de> a écrit:
> BTW, there is another dichotomy: child packages-haters vs. with-haters.
> Package dependencies introduced by children-parent relation are more
> evident and less arbitrary than ones by "with." The only problem is that
> multiple parents are not allowed.

It happened I though it would be nice if Ada required a With clause for  
parent package. Would be cleaner and safer IMHO.


-- 
“Syntactic sugar causes cancer of the semi-colons.”  [Epigrams on  
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
“c++; /* this makes c bigger but returns the old value */” [Anonymous]



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 19:38         ` Dmitry A. Kazakov
@ 2011-06-11 14:11           ` Yannick Duchêne (Hibou57)
  0 siblings, 0 replies; 33+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-06-11 14:11 UTC (permalink / raw)


Le Tue, 07 Jun 2011 21:38:32 +0200, Dmitry A. Kazakov  
<mailbox@dmitry-kazakov.de> a écrit:
> I would prefer stricter rules on
> declarations hiding each other (requiring explicit resolution of all
> conflicts) [*]. I definitely want a stronger than "use", transitive  
> clause
> to incorporate the declaration scope of a package into the scope of  
> another
> package. I would like to have multiple parents too.
>
> -----------------------
> * When people play this card against MI, they forget that packages allow
> exactly same. And if fully qualified names were a solution for packages,
> why it could not be for MI as well?
Yes, right. People frightened of MI seems to have not understood this is  
all about name conflict [*]. And we all know the way to solve this.

[*] And that is purely syntactical, this is not even conceptual! So MI is  
probably rejected mostly for syntactical-like matters.

-- 
“Syntactic sugar causes cancer of the semi-colons.”  [Epigrams on  
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
“c++; /* this makes c bigger but returns the old value */” [Anonymous]



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 17:33 ` Pascal Obry
  2011-06-08  2:42   ` Randy Brukardt
@ 2011-06-12  5:09   ` Yannick Duchêne (Hibou57)
  1 sibling, 0 replies; 33+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-06-12  5:09 UTC (permalink / raw)


Le Tue, 07 Jun 2011 19:33:29 +0200, Pascal Obry <pascal@obry.net> a écrit:
> in this case... Look at this code:
>
>     with Ada.Strings.Unbounded;
>     procedure Whatever is
>        S : Ada.Strings.Unbounded.Unbounded_String;
>     begin
>        Ada.Strings.Unbounded.Append (S, "toto");
>     end Whatever;
>
> Far better with:
>
>     with Ada.Strings.Unbounded;
>     procedure Whatever is
>        use Ada.Strings.Unbounded;
>        S : Unbounded_String;
>     begin
>        Append (S, "toto");
>     end Whatever;

You could also use package renaming, to access the leaf of a whole branch  
via a single short name. By the way, subprogram renaming is an option too  
in some cases (when a subprogram's invocation is very often encountered in  
some package body).

> Because Ada.Strings.Unbounded (and all Ada runtime packages) has been  
> designed to be used with a use clause.
>
> Now I do prefer:
>
>     package Circle is
>        type Object is...
>
> And use it as:
>
>     with Circle;
>
>     O : Circle.Object;

Good convention indeed. To talk about concrete matters, the name Instance  
may also be an option to have in mind along with the name Object (Instance  
may be more neutral, depending on one's feeling)

-- 
“Syntactic sugar causes cancer of the semi-colons.”  [Epigrams on  
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
“c++; /* this makes c bigger but returns the old value */” [Anonymous]



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 23:38 ` Shark8
@ 2011-06-12  5:19   ` Yannick Duchêne (Hibou57)
  2011-06-12  7:55   ` Stephen Leake
  1 sibling, 0 replies; 33+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-06-12  5:19 UTC (permalink / raw)


Le Wed, 08 Jun 2011 01:38:53 +0200, Shark8 <onewingedshark@gmail.com> a  
écrit:
> While this is true it can be handy for reducing prefix-clutter,
> as could a rename. So, while you may be hesitant to use them on the
> package, I find using them in declare-blocks and subprograms to be
> quite readable and usable.
>
> With
> Ada.Text_IO;
>
> Package Body Example is
>  [...]
>  Procedure Something_Interesting is
>    Use Ada.Text_IO; -- We're debugging here.
>  begin
>    [...]
>   Put_Line( "Debugging marker." );
>    [...]
>  end Something_interesting;
> End Example;
That's a common idiom in Jean Pierre Rosen's source ;)

> Ah, I like to use the comma-separated forms of use/with; this can be
> helpful if you wish to do a quick commenting out of a use or with to
> pass to the compiler and see if you really need it at all.
>
> EX:
> With
> Ada.Text_IO,
> --Ada.Integer_IO, -- Am I even using Ada.Integer_IO?
> --Ada.Tags,
> --MY_PARSING_PACKAGE,
> [...]
> MY_CONSOLE_MANIPULATION_PACKAGE
To talk again about him, you may also use his AdaDep tool for that purpose  
;)
Have a look: http://www.adalog.fr/compo2.htm#adadep

-- 
“Syntactic sugar causes cancer of the semi-colons.”  [Epigrams on  
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
“c++; /* this makes c bigger but returns the old value */” [Anonymous]



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 23:38 ` Shark8
  2011-06-12  5:19   ` Yannick Duchêne (Hibou57)
@ 2011-06-12  7:55   ` Stephen Leake
  1 sibling, 0 replies; 33+ messages in thread
From: Stephen Leake @ 2011-06-12  7:55 UTC (permalink / raw)


Shark8 <onewingedshark@gmail.com> writes:

> On Jun 7, 10:32 am, milouz <a.micheli...@gmail.com> 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.
>
> While this is true it can be handy for reducing prefix-clutter,
> as could a rename. So, while you may be hesitant to use them on the
> package, I find using them in declare-blocks and subprograms to be
> quite readable and usable.

This is my policy as well; 'use' clauses are forbidden in package specs,
and must be localized as much as possible in package bodies.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: using `use' : what is the best practice ?
  2011-06-07 15:32 using `use' : what is the best practice ? milouz
                   ` (7 preceding siblings ...)
  2011-06-08  6:06 ` stefan-lucks
@ 2011-06-15  2:25 ` Adrian Hoe
  8 siblings, 0 replies; 33+ messages in thread
From: Adrian Hoe @ 2011-06-15  2:25 UTC (permalink / raw)


On Jun 7, 11:32 pm, milouz <a.micheli...@gmail.com> 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') :
>
>    with P1; use P1;
>    with P2; use P2;
>
>    procedure Main is
>       My_Val : Integer;
>    begin
>       Foo(My_Val);  -- P1 or P2 ?
>    ...

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' :
>
>    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;


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



^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2011-06-15  2:25 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-07 15:32 using `use' : what is the best practice ? milouz
2011-06-07 15:59 ` Simon Wright
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

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