comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: using `use' : what is the best practice ?
Date: Tue, 7 Jun 2011 21:42:10 -0500
Date: 2011-06-07T21:42:10-05:00	[thread overview]
Message-ID: <ismni5$m5b$1@munin.nbi.dk> (raw)
In-Reply-To: 4DEE60E9.2020408@obry.net

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





  reply	other threads:[~2011-06-08  2:42 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
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 [this message]
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