* Re: Environment Variables
1997-01-21 0:00 Environment Variables John M. Greer
@ 1997-01-24 0:00 ` Matthew Heaney
1997-01-25 0:00 ` Robert Dewar
1997-01-24 0:00 ` Mike Bishop
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Matthew Heaney @ 1997-01-24 0:00 UTC (permalink / raw)
In article <5c1nf9$d3q@ultranews.duc.auburn.edu>, greerjo@mail.auburn.edu
(John M. Greer) wrote:
>Does anyone know how to access environment variables from Ada code?
>Specifically, Unix/Linux CGI environment variables from the latest
>version of GNAT.
Is POSIX supported on your machine. Did your compiler come with POSIX
bindings? If so, then environment variables are available via
POSIX_Process_Environment.
>On an unrelated note (and this is a classroom question, but it's not
>doing my homework for me), my professor commented that using WITH, though
>common in Ada-83, is frowned upon by the industry in Ada 95. Any
>specific reason for that? (I'm assuming name collisions with types that
>look similar to the compiler, but I've only been in this class for about
>a month, so . . .)
I'm not sure what you mean here. You *must* with other library units to
use the resources they provide. (Except of course for package Standard.)
When there's a name collision, Ada forces you the programmer to name the
unit containing the declaration so as to resolve the ambiguity. Ada never
makes a "default choice." (Though that's a bit of a lie in the case of
root types.)
Perhaps he was refering to the "use" clause?
Yes, this is a contentious issue in the Ada community. It's been my
experience, though, that the use clause it either used too often, or not
enough. There are a few techniques one can use that makes its use less
pernicious.
Your professor may have been refering to Ada 95's "use type" clause. This
obviates one reason why programmers use use, which was to gain direct
visibility to the operators of the type.
For example, if I have
package P is
type T is new Integer;
end;
with P;
procedure Proc is
O : P.T;
begin
O := O + 1;
The compiler complains because the "+" operator for the type isn't visible.
So you had a few choices.
with P; use P;
procedure Proc is
O : T;
begin
O := O + 1;
This is probably what your professor was refering to. If I'm in a scope
with a lot of variables and a lot of with's, then suddenly I don't know
where any of my types came from. A real maintenance nightmare, committed
by unthoughtful programmers.
Shops often ban the use of use for that reason, but it's a really naive
solution to the problem. So you have horrible code like this
with P;
procedure Proc is
O : P.T;
begin
O := P."+" (O, 1);
Ouch! A better solution (still Ada 83), is to use a renames:
with P;
procedure Proc is
O : P.T;
function "+" (L, R : P.T) return P.T renames P."+";
begin
O := O + 1;
At least now, everything is documented.
But if you're using a lot of operators, then renames can be a bit of a
chore. I like to localize the use clause, so at least I identify where the
type came from.
with P;
procedure Proc is
O : P.T;
use P;
begin
O := O + 1;
The (primitive) operations for a type are declared in the same package as
the type declaration, so if I identify the package containing the type,
then I've implicitly said where the operations (and operators) came from
too.
In Ada 95, there's a use type clause that allows me to get direct
visibility to the operators only:
with P; use type P.T;
procedure Proc is
O : P.T;
begin
O := O + 1;
Which seems to solve the problem to everyone's satisfaction.
The rules for use are as follows. To resolve the reference to the
operation, the compiler looks in successively outer scopes for an explicit
operation declaration or rename, until it hits the unit containing the type
declaration (where presumably the operation is primitive). The units named
in a use clause are considered only *after* this has been done.
Localizing a use clause only limits the scope to which the use clause
applies; it doesn't give the operations in the named unit any kind of
"priority" when resolving the reference. The operations of the unit named
in the use clause are still considered only after not finding explicit
declarations or renames, no matter how "near" it appears to the invokation
of the operation.
Few Ada programmers really understand the rules for use, which is partly
why it's use is so controversial.
Feel free to email me privately if you have any Ada questions. (Your
professor can email too, if he wants the opinion of an "industry
representative.")
matt
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Environment Variables
1997-01-21 0:00 Environment Variables John M. Greer
1997-01-24 0:00 ` Matthew Heaney
@ 1997-01-24 0:00 ` Mike Bishop
1997-01-25 0:00 ` Doug Smith
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Mike Bishop @ 1997-01-24 0:00 UTC (permalink / raw)
John M. Greer wrote:
>
> Does anyone know how to access environment variables from Ada code?
> Specifically, Unix/Linux CGI environment variables from the latest
> version of GNAT. (Yes, I'm writing CGI in Ada. Please don't write me
> and remind me that every newline requires a New_Line, as that seems to be
> a popular response to this question locally :-)
Have you looked at the Ada-to-CGI bindings, which can be found at
http://wuarchive.wustl.edu/languages/ada/swcomps/cgi/cgi.html? That may
help you out.
>
> On an unrelated note (and this is a classroom question, but it's not
> doing my homework for me), my professor commented that using WITH, though
> common in Ada-83, is frowned upon by the industry in Ada 95. Any
> specific reason for that? (I'm assuming name collisions with types that
> look similar to the compiler, but I've only been in this class for about
> a month, so . . .)
Using "with" is frowned upon in Ada 95? Is he referring to using "with"
for something like Ada.Text_IO, for example? Maybe he's talking about
not using "use". Having a lot of "use"s can clutter up a name space.
Even if the compiler can resolve all of the types, the differences
between similar types in different packages may not be obvious to a
maintainer.
--
Mike Bishop (mikeb@wizard.unitedspacealliance.com)
United Space Alliance
---------------------
The comments and opinions expressed are my own and
do not represent the views of United Space Alliance.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Environment Variables
1997-01-21 0:00 Environment Variables John M. Greer
1997-01-24 0:00 ` Matthew Heaney
1997-01-24 0:00 ` Mike Bishop
@ 1997-01-25 0:00 ` Doug Smith
1997-01-27 0:00 ` Frowining upon with clauses (was:Re: Environment Variables) Norman H. Cohen
1997-01-27 0:00 ` Environment Variables David Emery
4 siblings, 0 replies; 8+ messages in thread
From: Doug Smith @ 1997-01-25 0:00 UTC (permalink / raw)
In article <5c1nf9$d3q@ultranews.duc.auburn.edu>, greerjo@mail.auburn.edu (John M. Greer) wrote:
> Does anyone know how to access environment variables from Ada code?
> Specifically, Unix/Linux CGI environment variables from the latest
> version of GNAT. (Yes, I'm writing CGI in Ada. Please don't write me
> and remind me that every newline requires a New_Line, as that seems to be
> a popular response to this question locally :-)
[snip]
>
> John Greer
> (who vastly prefers Put to Ada.Text_IO.Put)
Check out the latest CGI binding used by WebAda at:
<http://sw-eng.falls-church.va.us/AdaIC/compilers/webada/source/cgi/>
Doug Smith
<mailto:dsmith@clark.net>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Frowining upon with clauses (was:Re: Environment Variables)
1997-01-21 0:00 Environment Variables John M. Greer
` (2 preceding siblings ...)
1997-01-25 0:00 ` Doug Smith
@ 1997-01-27 0:00 ` Norman H. Cohen
1997-02-08 0:00 ` Robert Dewar
1997-01-27 0:00 ` Environment Variables David Emery
4 siblings, 1 reply; 8+ messages in thread
From: Norman H. Cohen @ 1997-01-27 0:00 UTC (permalink / raw)
John M. Greer wrote:
> On an unrelated note (and this is a classroom question, but it's not
> doing my homework for me), my professor commented that using WITH, though
> common in Ada-83, is frowned upon by the industry in Ada 95. Any
> specific reason for that?
"Frowned upon" seems a bit overgeneral. Certainly there are packages
that are most appropriately written as child packages in Ada 95, and in
Ada 83 such packages would have had to been written as independent
packages gain access to the facilities of the "parent package" through a
with clause.
--
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Frowining upon with clauses (was:Re: Environment Variables)
1997-01-27 0:00 ` Frowining upon with clauses (was:Re: Environment Variables) Norman H. Cohen
@ 1997-02-08 0:00 ` Robert Dewar
0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1997-02-08 0:00 UTC (permalink / raw)
Norman says, answering John
<<> On an unrelated note (and this is a classroom question, but it's not
> doing my homework for me), my professor commented that using WITH, though
> common in Ada-83, is frowned upon by the industry in Ada 95. Any
> specific reason for that?
"Frowned upon" seems a bit overgeneral. Certainly there are packages
that are most appropriately written as child packages in Ada 95, and in
Ada 83 such packages would have had to been written as independent
packages gain access to the facilities of the "parent package" through a
with clause.
>>
Surely John is confusing WITH with USE, I cannot imagine anyone who knows
anything at all about Ada saying tha the use of WITH is frowned upon,
whereas it is quite true that many Ada programmers prefer to avoid USE (a
subject on which we do *not* need another thread I think!)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Environment Variables
1997-01-21 0:00 Environment Variables John M. Greer
` (3 preceding siblings ...)
1997-01-27 0:00 ` Frowining upon with clauses (was:Re: Environment Variables) Norman H. Cohen
@ 1997-01-27 0:00 ` David Emery
4 siblings, 0 replies; 8+ messages in thread
From: David Emery @ 1997-01-27 0:00 UTC (permalink / raw)
Of course, if you want to be POSIX-compliant, you should use
POSIX_Process_Environment....
dave
--
Note: if email to me bounces, use 'emery@grebyn.com'
^ permalink raw reply [flat|nested] 8+ messages in thread