comp.lang.ada
 help / color / mirror / Atom feed
* Why both "with" and "use"?
@ 1999-02-13  0:00 Mike Silva
  1999-02-13  0:00 ` Corey Minyard
                   ` (2 more replies)
  0 siblings, 3 replies; 55+ messages in thread
From: Mike Silva @ 1999-02-13  0:00 UTC (permalink / raw)


Somebody on comp.lang.fortran noticed these two lines in an Ada snippet
and questioned why both lines were needed (vs. only USE in Fortran).

>with Ada.Numerics.Elementary_Functions;
>use  Ada.Numerics.Elementary_Functions;

I, with two whole weeks of Ada experience, understand the difference
(sorta) but don't really understand the rationale.  Would anybody care
to explain the why of it?  Thanks.

Mike




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00 Why both "with" and "use"? Mike Silva
  1999-02-13  0:00 ` Corey Minyard
@ 1999-02-13  0:00 ` Pat Rogers
  1999-02-13  0:00   ` bill
  1999-02-15  0:00 ` Jean-Pierre Rosen
  2 siblings, 1 reply; 55+ messages in thread
From: Pat Rogers @ 1999-02-13  0:00 UTC (permalink / raw)


Mike Silva wrote in message <36C5B28C.F32C43A4@jps.net>...
>Somebody on comp.lang.fortran noticed these two lines in an Ada
snippet
>and questioned why both lines were needed (vs. only USE in Fortran).
>
>>with Ada.Numerics.Elementary_Functions;
>>use  Ada.Numerics.Elementary_Functions;
>
>I, with two whole weeks of Ada experience, understand the difference
>(sorta) but don't really understand the rationale.  Would anybody
care
>to explain the why of it?  Thanks.


The "with clause" and "use clause" are part of a "context clause".   I
think of a context clause as meaning "compile the unit in question in
the *context* of these units mentioned in the context clause".

Specifically, the "with clause" means the unit being compiled will
reference the unit named in the clause.  It is somewhat like an
"import" clause in some languages.  In fact, I always say "import"
when I need to use "with" as a verb (e.g., "We need to import
Text_IO.").  Broadly, if a compilation unit references another
independent unit, the "with clause" is required -- the compiler won't
compile the references otherwise.  Mainly one imports packages, but
other program units can be imported as well, especially generic units.
Subprograms can be imported too, although people seem to forget that
subprograms can have separate declarations at the library level.

So if we say:

    with Ada.Text_IO;

we are saying "the compilation unit that follows will make references
to Ada.Text_IO.".

The "use clause", on the other hand, provides *direct* visibility into
the declarations exported from a package, that would otherwise not be
directly visible.  As such, "use clauses" are optional.  Direct
visibility is the purpose of the clause -- without it, the things
inside the imported package can only be referenced indirectly via the
full name, which includes the package name:

    Ada.Text_IO.Put_Line( "This is a call to a procedure named
Put_Line" );

When the "use clause" is applied to Ada.Text_IO, we can reference the
declarations directly, without including the package name:

    Put_Line( "This is a call to a the same procedure named
Put_Line" );

People tend to have strong feelings about whether or not (or how much)
"use clauses" should be applied.  That's a subject for another post.
:-)

Sometimes people get confused when they see both clauses together, as
in

    with Ada.Text_IO;
    use  Ada.Text_IO;

    package Foo is ...

The issue is that "with clauses" connect independent units, and thus
go outside of them ("between them", if you will).  On the other hand,
"use clauses" can be placed *inside* units as well as outside, in both
cases providing direct visibility from that point on down to the end
of the unit (more or less).  Placing a "use clause" outside of the
compilation unit (i.e. right after the "with clause") just means that
direct visibility to the exported declarations is available throughout
the compilation unit, as if we had placed it immediately within the
compilation unit before anything else.

    with Ada.Text_IO;

    package Foo is

        use  Ada.Text_IO;

        ...

    end Foo;

So, the two clauses serve different purposes, and have different
placement requirements, but are related because they allow and control
visibility -- indirect visibility via "with clauses", and direct
visibility via "use clauses".  One is required, the other optional.

Hope that helps,

---
Pat Rogers                          Training & Development in:
http://www.classwide.com    Deadline Schedulability Analysis
progers@acm.org                 Software Fault Tolerance
(281)648-3165                       Real-Time/OO Languages






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

* Re: Why both "with" and "use"?
  1999-02-13  0:00 Why both "with" and "use"? Mike Silva
@ 1999-02-13  0:00 ` Corey Minyard
  1999-02-13  0:00   ` Matthew Heaney
  1999-02-13  0:00   ` mike
  1999-02-13  0:00 ` Pat Rogers
  1999-02-15  0:00 ` Jean-Pierre Rosen
  2 siblings, 2 replies; 55+ messages in thread
From: Corey Minyard @ 1999-02-13  0:00 UTC (permalink / raw)


Mike Silva <mjsilva@jps.net> writes:

> Somebody on comp.lang.fortran noticed these two lines in an Ada snippet
> and questioned why both lines were needed (vs. only USE in Fortran).
> 
> >with Ada.Numerics.Elementary_Functions;
> >use  Ada.Numerics.Elementary_Functions;
> 
> I, with two whole weeks of Ada experience, understand the difference
> (sorta) but don't really understand the rationale.  Would anybody care
> to explain the why of it?  Thanks.
> 
> Mike

Although I'm not in the league of others in this group, I'll give my
opinion.

The with clause allows things in the "withed" to be used explicitly
with their name with the package preceding, such as

  X := Ada.Numerics.Elementary_Functions.Sqrt(10.0);

The use clause generally (but not always) causes things to be
available with the name only, such as

  X := Sqrt(10.0);

If there were another function named Sqrt in another "used" package that
took the same type argument(s), the whole name would still be necessary
so the compiler could tell which one to use.

I hardly ever use "use" clauses any more, just "use type" clauses when
necessary.  When you develop a large system, it becomes difficult to
find where something is declared.  In this particular example, I would
probably use the "use" clause because the source would be obvious to
any good Ada programmer.  But in most cases, being able to know the
package the item is declared in is quite useful.  I've look at far too
many C programs where I spend most of my time finding where functions
are declared.  A well written Ada program won't have nearly as big a
problem with that.

It can make the code messy to have huge names, so I'll sometimes use
package renaming to shorten the names and still retain clarity.  But
it can be a balancing act sometimes.  The whole thing is a balancing

Hope this helps.

-- 
Corey Minyard                   Internet:  minyard@acm.org
  Work: minyard@nortelnetworks.com  UUCP:  minyard@wf-rch.cirr.com




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00 ` Pat Rogers
@ 1999-02-13  0:00   ` bill
  1999-02-13  0:00     ` Pat Rogers
                       ` (2 more replies)
  0 siblings, 3 replies; 55+ messages in thread
From: bill @ 1999-02-13  0:00 UTC (permalink / raw)


In article <7a4f85$rh1$1@remarQ.com>, "Pat says...
>
 
..good stuff snipped..

thanks for the nice review.

Just to compare this to Java, in Java, almost everyone does something
like this:

import package_name;*

this imports, and at the same time, makes visible all class in package
and all public entities in all classes.

One can import one specific class from the package:

import package_name.class_name

And this also combines importing and making directly visible all public
entities in the class. 

Also, in Java a package seems to have different purpose than with Ada. In
Java a package is a collection of classes. In OO Ada, a package usually
contains one tagged type. or is this not the normal practice?

I feel that the Ada package and the "with" and the "use" give better
control of things. Not only that, the fact that in Java, one can
compile a program that uses some class, but becuase classes
are loaded at run time, it is possible to load the old byte code of
compiled against class if the class path is wrong, or if the new byte
code for the compiled class was not jarred correctly.  I fee the whole
development and software packaging with Java is a pain and can lead to
errors. In classical development (as in C/C++/Ada etc..) these kinds
of problems do not happen as much (even with dynamic shared libraries,
there is a check done against version numbers of libraries at load/run
time to make sure the correct library code is loaded).

Bill




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00   ` bill
@ 1999-02-13  0:00     ` Pat Rogers
  1999-02-13  0:00       ` Matthew Heaney
  1999-02-13  0:00     ` Matthew Heaney
  1999-02-15  0:00     ` Jean-Pierre Rosen
  2 siblings, 1 reply; 55+ messages in thread
From: Pat Rogers @ 1999-02-13  0:00 UTC (permalink / raw)


bill wrote in message <7a4j3h$64e@drn.newsguy.com>...

<snip>

>Also, in Java a package seems to have different purpose than with
Ada. In
>Java a package is a collection of classes. In OO Ada, a package
usually
>contains one tagged type. or is this not the normal practice?


A package serves more of a central purpose in Ada 95, especially when
it exports a tagged type declaration.

The big difference (or, at least one difference) between Java packages
and Ada packages is that the combination of an Ada package and a
private type defines an Abstract Data Type.  An ADT is defined as a
set of legal operations and legal values, and little else.  In Ada
these legal operations are called "primitive operations".  The
primitive operations are those subprograms that are both declared
*with* the type in the *same* package and that manipulate values of
the type as either formal parameters or (for functions) result types.
It is these primitive operations that are inherited during derivation,
and only they can be dispatched to, dynamically, at run-time.

An OOP object is really just an ADT plus run-time polymorphism, and a
private (tagged) type defines an ADT.  You can't have private types
without packages, so packages are critical to OOP with Ada.  Note that
tagged types need not be private, but the encapsulation provided by
private types is considered a central characteristic of objects in
OOP.

---
Pat Rogers                          Training & Development in:
http://www.classwide.com    Deadline Schedulability Analysis
progers@acm.org                 Software Fault Tolerance
(281)648-3165                       Real-Time/OO Languages







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

* Re: Why both "with" and "use"?
  1999-02-13  0:00   ` bill
  1999-02-13  0:00     ` Pat Rogers
@ 1999-02-13  0:00     ` Matthew Heaney
  1999-02-15  0:00     ` Jean-Pierre Rosen
  2 siblings, 0 replies; 55+ messages in thread
From: Matthew Heaney @ 1999-02-13  0:00 UTC (permalink / raw)


bill <bill@newsguy.com> writes:

> Also, in Java a package seems to have different purpose than with Ada. In
> Java a package is a collection of classes. In OO Ada, a package usually
> contains one tagged type. or is this not the normal practice?

A package exports a collection of entities that are "highly cohesive."
As such, it often makes sense to bundle types together in the same
package.  For example:

generic
  type Item_Type is private;
package Stacks is

   type Stack_Type is limited private;

   procedure Push 
     (Item : in     Item_Type;
      On   : in out Stack_Type);

   <etc>

   
   type Stack_Iterator is private;

   function Initialize 
     (Stack : Stack_Type) return Stack_Iterator;

   function Get_Item
     (Iterator : Stack_Iterator) return Item_Type;

   procedure Advance 
     (Iterator : in out Stack_Iterator);

  <etc>

end Stacks;


Here, we have an example of a stack type and its iterator type, together
in one package.  This is entirely natural and appropriate.






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

* Re: Why both "with" and "use"?
  1999-02-13  0:00     ` Pat Rogers
@ 1999-02-13  0:00       ` Matthew Heaney
  1999-02-13  0:00         ` bill
                           ` (2 more replies)
  0 siblings, 3 replies; 55+ messages in thread
From: Matthew Heaney @ 1999-02-13  0:00 UTC (permalink / raw)


"Pat Rogers" <progers@NOclasswideSPAM.com> writes:

> A package serves more of a central purpose in Ada 95, especially when
> it exports a tagged type declaration.
> 
> The big difference (or, at least one difference) between Java packages
> and Ada packages is that the combination of an Ada package and a
> private type defines an Abstract Data Type.

I wouldn't quite phrase it that way.  With respect to the declaration of
a type (and I mean _any_ kind of type, not just ADTs), the package in
which the type is declared serves to demarcate, among all the operations
in the universe that can take objects of that type as a parameter or
return value, those operations that are "primitive" for the type.

Perhaps I am being pedantic, but I don't regard a package as part of a
type.  I regard the type as its name, values, and (primitive)
operations.  The package is just syntactic overhead necessary to
identify the primitive operations, but the package itself is not part of
the type.

When they give me a bag at the supermarket to hold my groceries, it's the
groceries that I am interested in, not the bag.  If I were to make a
list of the things I picked up at the store, I probably wouldn't include
the bag in that list.




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00 ` Corey Minyard
@ 1999-02-13  0:00   ` Matthew Heaney
  1999-02-13  0:00     ` bill
                       ` (2 more replies)
  1999-02-13  0:00   ` mike
  1 sibling, 3 replies; 55+ messages in thread
From: Matthew Heaney @ 1999-02-13  0:00 UTC (permalink / raw)


Corey Minyard <minyard@acm.org> writes:

> But in most cases, being able to know the package the item is declared
> in is quite useful.

Yes, this is true, but not using a use clause isn't the only way to
effect this goal.  Careful naming conventions make the origin of the
entity obvious, in spite of the presence of a use clause.

For example:

package Digitizer_Id_Types is

   type Digitizer_Id is range 1 .. 2;

end Digitizer_Id_Types;


with Digitizer_Id_Types;  use Digitizer_Id_Types;
...

   Digitizer : Digitizer_Id;


It's pretty obvious that type Digitizer_Id comes from package
Digitizer_Id_Types.  No amount of package renaming or subtype
declarations are going to make it any more obvious.

These days, I hardly ever don't use a use clause, and I've formed the
tentative opinion that Ada should have defined the with clause to have
the semantics of both with and use.





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

* Re: Why both "with" and "use"?
  1999-02-13  0:00   ` Matthew Heaney
  1999-02-13  0:00     ` bill
@ 1999-02-13  0:00     ` Tom Moran
  1999-02-14  0:00       ` Matthew Heaney
  1999-02-16  0:00     ` Samuel Mize
  2 siblings, 1 reply; 55+ messages in thread
From: Tom Moran @ 1999-02-13  0:00 UTC (permalink / raw)


>package Digitizer_Id_Types is

>   type Digitizer_Id is range 1 .. 2;

>end Digitizer_Id_Types;


>with Digitizer_Id_Types;  use Digitizer_Id_Types;
>...

>   Digitizer : Digitizer_Id;
alternatively, you could do
 package Digitizers is
   type ID is range 1 .. 2;
   ...
end Digitizers;
with Digitizers;
...
  Digitizer : Digitizers.ID;
which would leave out the Use clause, let the compiler help make sure
the naming is right, and let the maintainer or simple minded source
code tool easily spot the origin of Digitizers.ID.
  




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00       ` Matthew Heaney
@ 1999-02-13  0:00         ` bill
  1999-02-14  0:00         ` Pat Rogers
  1999-02-16  0:00         ` Samuel Mize
  2 siblings, 0 replies; 55+ messages in thread
From: bill @ 1999-02-13  0:00 UTC (permalink / raw)


In article <m3ogmxuctb.fsf@mheaney.ni.net>, Matthew says...
 
>
>Perhaps I am being pedantic, but I don't regard a package as part of a
>type.  

No, you are not being pedantic. I think this is the correct way to look
at too.

>The package is just syntactic overhead necessary to
>identify the primitive operations, but the package itself is not part of
>the type.
>
>When they give me a bag at the supermarket to hold my groceries, it's the
>groceries that I am interested in, not the bag.  If I were to make a
>list of the things I picked up at the store, I probably wouldn't include
>the bag in that list.

Nice way to express this idea.

This makes it also sound you'll be happy with the 'namespace' construct
in C++. Many people use a namespace to inclose in it other classes or
even other namespaces, to help organize the contents of the
"supermarket" bag.

actually I like the 'namespace' more than the Java package. Java packages
are also physically tied to directory structure, which is annoying to me, i.e.
package A.B.PackageX, must live is  A/B/PackageX  directory somewhere on
the disk. While Ada packages and C++ namespaces has nothing to do with
where the actuall code can be found.

I think Java did it that way to help the JVM located the bytecode file at
run-time.

Bill




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00   ` Matthew Heaney
@ 1999-02-13  0:00     ` bill
  1999-02-14  0:00       ` dewar
                         ` (2 more replies)
  1999-02-13  0:00     ` Tom Moran
  1999-02-16  0:00     ` Samuel Mize
  2 siblings, 3 replies; 55+ messages in thread
From: bill @ 1999-02-13  0:00 UTC (permalink / raw)


In article <m3lni1ucb9.fsf@mheaney.ni.net>, Matthew says...
>
>Corey Minyard <minyard@acm.org> writes:
>
>> But in most cases, being able to know the package the item is declared
>> in is quite useful.
>

>Yes, this is true, but not using a use clause isn't the only way to
>effect this goal.  Careful naming conventions make the origin of the
>entity obvious, in spite of the presence of a use clause.
>

it would be nice to have a smart editor that is context senstive, where
if you point the mouse to a name and say right-click, it will show 
properties of the thing pointed to, such as it type, the package it came from,
etc.. 

This way, one can have their cake and eat too. One can use 'use', but still
know from which packages things came from by simple point/click.

offcourse this editor must be free sourced and GPL'ed :) so eveyone can use it.
wonder if it possible to do such a thing with xemacs...

Bill 




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00 ` Corey Minyard
  1999-02-13  0:00   ` Matthew Heaney
@ 1999-02-13  0:00   ` mike
  1 sibling, 0 replies; 55+ messages in thread
From: mike @ 1999-02-13  0:00 UTC (permalink / raw)


In article <m2socaxfjw.fsf@wf-rch.cirr.com>, Corey says...
 
>I've look at far too
>many C programs where I spend most of my time finding where functions
>are declared.  

You could have saved all this time by using a tool (which its name
escapes me right now). The idea is to build an indexed database of
the source code, then you can use it to look for things. It is 
very fast. You can ask it things like:

find where this variable/function is defined.
find all header files used by a C file
etc.. many more things. I've used it about 2 years ago. it was made
by Bell Labs then. it was not free. but you could buy the source code.  

mike
 




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00     ` Tom Moran
@ 1999-02-14  0:00       ` Matthew Heaney
  0 siblings, 0 replies; 55+ messages in thread
From: Matthew Heaney @ 1999-02-14  0:00 UTC (permalink / raw)


tmoran@bix.com (Tom Moran) writes:

> alternatively, you could do
>  package Digitizers is
>    type ID is range 1 .. 2;
>    ...
> end Digitizers;
> with Digitizers;
> ...
>   Digitizer : Digitizers.ID;
> which would leave out the Use clause, let the compiler help make sure
> the naming is right, and let the maintainer or simple minded source
> code tool easily spot the origin of Digitizers.ID.

This won't work, because you need the types to be separate from the
Digitizers package.  The organization looks something like this:

with Digitizer_Id_Types; use Digitizer_Id_Types;

package Digitizers is

  procedure Set_Mode (Id : in Digitizer_Id);

...

end Digitizers;


There are clients of Digitizer_Id who are not clients of Digitizers, and
they have to be protected from the volatility of the Digitizers package,
or you end up recompiling the universe every day.






   




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00     ` bill
  1999-02-14  0:00       ` dewar
  1999-02-14  0:00       ` dewar
@ 1999-02-14  0:00       ` Matthew Heaney
  2 siblings, 0 replies; 55+ messages in thread
From: Matthew Heaney @ 1999-02-14  0:00 UTC (permalink / raw)


bill <bill@newsguy.com> writes:

> it would be nice to have a smart editor that is context senstive,
> where if you point the mouse to a name and say right-click, it will
> show properties of the thing pointed to, such as it type, the package
> it came from, etc..
> 
> This way, one can have their cake and eat too. One can use 'use', but
> still know from which packages things came from by simple point/click.
> 
> offcourse this editor must be free sourced and GPL'ed :) so eveyone
> can use it.  wonder if it possible to do such a thing with xemacs...

Yes, it certainly is possible using (x)emacs (with gnat): it's called
ada-xref.el.

If you're sitting on an entity, then M-x ada-goto-declaration (usually
bound to C-c C-d) will move point to the file containing the
declaration.

I re-wrote the version of ada-xref.e. that came with ada-mode versions
earlier than 3.0 (the one done by ACT), because it basically didn't
work.  I haven't used the new version of GNAT yet, so I don't know
whether they fixed it or not.  If anyone is interested, let me know and
I'll send it to you.







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

* Re: Why both "with" and "use"?
  1999-02-13  0:00     ` bill
  1999-02-14  0:00       ` dewar
@ 1999-02-14  0:00       ` dewar
  1999-02-14  0:00       ` Matthew Heaney
  2 siblings, 0 replies; 55+ messages in thread
From: dewar @ 1999-02-14  0:00 UTC (permalink / raw)


In article <7a529a$t54@drn.newsguy.com>,
  bill <bill@newsguy.com> wrote:

> it would be nice to have a smart editor that is context
> senstive, where if you point the mouse to a name and say
> right-click, it will show properties of the thing pointed
> to, such as it type, the package it came from, etc.

You can get this functionality using GNAPSE (one of the
development environments available for GNAT,
based on EMACS Ada mode). Using
this editor, you can go immediately from a reference to
the declaration in the source (which presumably, together
with its comments tells you the properties you are looking
for). This functionality is based on the cross-reference
information that is now placed by default into ali files.
Note that this will only work with GNAT, since it depends
on this information.

> This way, one can have their cake and eat too. One can
> use 'use', but still know from which packages things came
> from by simple point/click.

There is no course of doubt that the choice of whether to
use the use clause is influenced by the presence of such
tools. However, that's not the whole story. A lot depends
on the names. If a package like Posix has a function called
Error, then you probably want to say Posix.Error anyway, if
the function is called Posix_Error, then it makes better
sense to USE Posix, so naming choices are definitely a
factor here.
>
> offcourse this editor must be free sourced and GPL'ed :)
> so eveyone can use it. wonder if it possible to do such a
> thing with xemacs...

This is a bit confused. I would guess what you are
interested in is that this tool be freely and publicly
available. But the GPL is neither necessary nor sufficient
to achieve this. Remember that the GPL never forces anyone
to distribute anything at any time for any reason. It is
about what you can do *if* you have the software and hold
the license.

The fact that there are public releases of GNAT (and indeed
of the GNAPSE technology mentioned above) is a result of
Ada Core Technology's policy of making free releases, not
of the GPL per se.

It would be legally possible for ACT to make the next
release of GNAT much more proprietary (e.g. by abandoning
the GPL on those parts that are copyright ACT), but of
course we have no intention of doing this, and we are
absolutely committed to periodic public releases of all
our GNAT-related technology.

I mention this because I am constantly running into people
who think that the GPL forces you to distribute things. As
an example (ACT is really not a good one, since we always
distribute everything publicly anyway), consider a company
that gets hold of GNAT, and then makes an extension for its
own use. There is absolutely no obligation of any kind for
that company to distribute this extension publicly. This is
true even if the company distributes copies of this
extension to a small number of companies it works with.
In the latter case, neither the original author, nor the
companies that have copies have any obligation whatsoever
to distribute.

This is an important point, because some other proposed
"open source" licenses have suggested that some kind of
distribution (e.g. at least distribution back to the
original author) would be required.

But such a distribution requirement goes against the idea
of "freedom" in free software. The whole idea is that you
can use the software in anyway you want, including
modifying it for yourself and not distributing it. The
only thing you can't do is to take away this freedom from
others, so when you distribute the software, in either its
original form, or modified, the recipient must have the
same freedoms. It's sort of like a democracy in which the
people can vote for anything except to take away the vote
from succeeding generations.

Anyway, this is all theoretical in this case, the GNAPSE
capability that I mention above is indeed available with
the publicly available 3.11p release of GNAT. Try it out!

Robert Dewar
Ada Core Technologies

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00     ` bill
@ 1999-02-14  0:00       ` dewar
  1999-02-14  0:00       ` dewar
  1999-02-14  0:00       ` Matthew Heaney
  2 siblings, 0 replies; 55+ messages in thread
From: dewar @ 1999-02-14  0:00 UTC (permalink / raw)


In article <7a529a$t54@drn.newsguy.com>,
  bill <bill@newsguy.com> wrote:

> it would be nice to have a smart editor that is context
> senstive, where if you point the mouse to a name and say
> right-click, it will show properties of the thing pointed
> to, such as it type, the package it came from, etc.

You can get this functionality using GNAPSE (one of the
development environments available for GNAT,
based on EMACS Ada mode). Using
this editor, you can go immediately from a reference to
the declaration in the source (which presumably, together
with its comments tells you the properties you are looking
for). This functionality is based on the cross-reference
information that is now placed by default into ali files.
Note that this will only work with GNAT, since it depends
on this information.

> This way, one can have their cake and eat too. One can
> use 'use', but still know from which packages things came
> from by simple point/click.

There is no course of doubt that the choice of whether to
use the use clause is influenced by the presence of such
tools. However, that's not the whole story. A lot depends
on the names. If a package like Posix has a function called
Error, then you probably want to say Posix.Error anyway, if
the function is called Posix_Error, then it makes better
sense to USE Posix, so naming choices are definitely a
factor here.
>
> offcourse this editor must be free sourced and GPL'ed :)
> so eveyone can use it. wonder if it possible to do such a
> thing with xemacs...

This is a bit confused. I would guess what you are
interested in is that this tool be freely and publicly
available. But the GPL is neither necessary nor sufficient
to achieve this. Remember that the GPL never forces anyone
to distribute anything at any time for any reason. It is
about what you can do *if* you have the software and hold
the license.

The fact that there are public releases of GNAT (and indeed
of the GNAPSE technology mentioned above) is a result of
Ada Core Technology's policy of making free releases, not
of the GPL per se.

It would be legally possible for ACT to make the next
release of GNAT much more proprietary (e.g. by abandoning
the GPL on those parts that are copyright ACT), but of
course we have no intention of doing this, and we are
absolutely committed to periodic public releases of all
our GNAT-related technology.

I mention this because I am constantly running into people
who think that the GPL forces you to distribute things. As
an example (ACT is really not a good one, since we always
distribute everything publicly anyway), consider a company
that gets hold of GNAT, and then makes an extension for its
own use. There is absolutely no obligation of any kind for
that company to distribute this extension publicly. This is
true even if the company distributes copies of this
extension to a small number of companies it works with.
In the latter case, neither the original author, nor the
companies that have copies have any obligation whatsoever
to distribute.

This is an important point, because some other proposed
"open source" licenses have suggested that some kind of
distribution (e.g. at least distribution back to the
original author) would be required.

But such a distribution requirement goes against the idea
of "freedom" in free software. The whole idea is that you
can use the software in anyway you want, including
modifying it for yourself and not distributing it. The
only thing you can't do is to take away this freedom from
others, so when you distribute the software, in either its
original form, or modified, the recipient must have the
same freedoms. It's sort of like a democracy in which the
people can vote for anything except to take away the vote
from succeeding generations.

Anyway, this is all theoretical in this case, the GNAPSE
capability that I mention above is indeed available with
the publicly available 3.11p release of GNAT. Try it out!

Robert Dewar
Ada Core Technologies

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00       ` Matthew Heaney
  1999-02-13  0:00         ` bill
@ 1999-02-14  0:00         ` Pat Rogers
  1999-02-14  0:00           ` Bob Collins
  1999-02-16  0:00         ` Samuel Mize
  2 siblings, 1 reply; 55+ messages in thread
From: Pat Rogers @ 1999-02-14  0:00 UTC (permalink / raw)


Matthew Heaney wrote in message ...
>"Pat Rogers" <progers@NOclasswideSPAM.com> writes:
>
>> A package serves more of a central purpose in Ada 95, especially
when
>> it exports a tagged type declaration.
>>
>> The big difference (or, at least one difference) between Java
packages
>> and Ada packages is that the combination of an Ada package and a
>> private type defines an Abstract Data Type.
>
>I wouldn't quite phrase it that way.  With respect to the declaration
of
>a type (and I mean _any_ kind of type, not just ADTs), the package in
>which the type is declared serves to demarcate, among all the
operations
>in the universe that can take objects of that type as a parameter or
>return value, those operations that are "primitive" for the type.

Yes, I believe that is what I said (in a part you've snipped).

>Perhaps I am being pedantic, but I don't regard a package as part of
a
>type.  I regard the type as its name, values, and (primitive)
>operations.  The package is just syntactic overhead necessary to
>identify the primitive operations, but the package itself is not part
of
>the type.


Yes, the package isn't part of the type itself, but let's go back for
a moment to the definition I gave of an ADT: "a set of legal
operations (the "primitives") and legal values, and little else."  It
is the "little else" that packages provide, and IMHO and ADT without
that aspect is not an ADT.  We're in agreement overall, of course, but
I think it is important to stress that, in addition to the demarcation
of the primitives, as you've said above, the encapsulation of the
type's representation is an essential aspect of an ADT.  Without
packages, we have no encapsulation, no information hiding.

---
Pat Rogers                          Training & Development in:
http://www.classwide.com    Deadline Schedulability Analysis
progers@acm.org                 Software Fault Tolerance
(281)648-3165                       Real-Time/OO Languages






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

* Re: Why both "with" and "use"?
  1999-02-14  0:00         ` Pat Rogers
@ 1999-02-14  0:00           ` Bob Collins
  1999-02-14  0:00             ` Pat Rogers
  0 siblings, 1 reply; 55+ messages in thread
From: Bob Collins @ 1999-02-14  0:00 UTC (permalink / raw)


In article <7a6jho$nkv$1@remarQ.com>, "Pat Rogers"
<progers@NOclasswideSPAM.com> wrote:

> Yes, the package isn't part of the type itself, but let's go back for
> a moment to the definition I gave of an ADT: "a set of legal
> operations (the "primitives") and legal values, and little else."  It
> is the "little else" that packages provide, and IMHO and ADT without
> that aspect is not an ADT.  We're in agreement overall, of course, but
> I think it is important to stress that, in addition to the demarcation
> of the primitives, as you've said above, the encapsulation of the
> type's representation is an essential aspect of an ADT.  Without
> packages, we have no encapsulation, no information hiding.

In the Guttag-Horning-Liskov formulations of the algebraic
specifications of ADTs, errors were important values. The
Ada package allows errors in ADTs very naturally, as exceptions
declared inside the package. Every stack ADT need an Empty_Stack
exception declaration for completeness as an ADT and possibly
a Stack_Overflow exception declaration as a practical convenience.

These are the kinds of things that are more than the "little else"
mentioned above. Also, when the TOI (type of interest) in each of
two type algebras is a supporting type in the other, it is
programmatically convenient to include both ADTs in the same
package. In this thread, we've already seen an example of a structure
and its iterator in the same package.

-- 
Bob Collins  <mailto:collins@cs.wm.edu>  <http://ratbert.cs.wm.edu>




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

* Re: Why both "with" and "use"?
  1999-02-14  0:00           ` Bob Collins
@ 1999-02-14  0:00             ` Pat Rogers
  0 siblings, 0 replies; 55+ messages in thread
From: Pat Rogers @ 1999-02-14  0:00 UTC (permalink / raw)


Bob Collins wrote in message ...
>In article <7a6jho$nkv$1@remarQ.com>, "Pat Rogers"
><progers@NOclasswideSPAM.com> wrote:
>
>> Yes, the package isn't part of the type itself, but let's go back
for
>> a moment to the definition I gave of an ADT: "a set of legal
>> operations (the "primitives") and legal values, and little else."
It
>> is the "little else" that packages provide, and IMHO and ADT
without
>> that aspect is not an ADT.  We're in agreement overall, of course,
but
>> I think it is important to stress that, in addition to the
demarcation
>> of the primitives, as you've said above, the encapsulation of the
>> type's representation is an essential aspect of an ADT.  Without
>> packages, we have no encapsulation, no information hiding.
>
>In the Guttag-Horning-Liskov formulations of the algebraic
>specifications of ADTs, errors were important values. The
>Ada package allows errors in ADTs very naturally, as exceptions
>declared inside the package. Every stack ADT need an Empty_Stack
>exception declaration for completeness as an ADT and possibly
>a Stack_Overflow exception declaration as a practical convenience.
>
>These are the kinds of things that are more than the "little else"
>mentioned above. Also, when the TOI (type of interest) in each of
>two type algebras is a supporting type in the other, it is
>programmatically convenient to include both ADTs in the same
>package. In this thread, we've already seen an example of a structure
>and its iterator in the same package.


I fail to see how the above argues against my point that encapsulation
(provided by the package) is a necessary aspect of an ADT.  No one
would argue that error conditions are not part of the ADT interface.
My point is that the operations available due to the type's
representation are available unless the package prevents it, and such
operations are *not* part of the interface.

---
Pat Rogers                          Training & Development in:
http://www.classwide.com    Deadline Schedulability Analysis
progers@classwide.com         Software Fault Tolerance
(281)648-3165                       Real-Time/OO Languages

>
>--
>Bob Collins  <mailto:collins@cs.wm.edu>  <http://ratbert.cs.wm.edu>






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

* Re: Why both "with" and "use"?
  1999-02-13  0:00 Why both "with" and "use"? Mike Silva
  1999-02-13  0:00 ` Corey Minyard
  1999-02-13  0:00 ` Pat Rogers
@ 1999-02-15  0:00 ` Jean-Pierre Rosen
  2 siblings, 0 replies; 55+ messages in thread
From: Jean-Pierre Rosen @ 1999-02-15  0:00 UTC (permalink / raw)


>Somebody on comp.lang.fortran noticed these two lines in an Ada
snippet
>and questioned why both lines were needed (vs. only USE in Fortran).
>
>>with Ada.Numerics.Elementary_Functions;
>>use  Ada.Numerics.Elementary_Functions;
>
>I, with two whole weeks of Ada experience, understand the difference
>(sorta) but don't really understand the rationale.  Would anybody
care
>to explain the why of it?  Thanks.
>
A short explanation:
A with is at compilation unit. It means: somewhere in unit "Foo",
something from "Bar" will be used.
A use is local. It tells: here is where I really need "Bar".

As an analogy, if you are preparing for a trek, you must take all your
food WITH you. However, you open the cans only when you want to USE
them.
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://perso.wanadoo.fr/adalog






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

* Re: Why both "with" and "use"?
  1999-02-13  0:00   ` bill
  1999-02-13  0:00     ` Pat Rogers
  1999-02-13  0:00     ` Matthew Heaney
@ 1999-02-15  0:00     ` Jean-Pierre Rosen
  1999-02-15  0:00       ` Ed Falis
  2 siblings, 1 reply; 55+ messages in thread
From: Jean-Pierre Rosen @ 1999-02-15  0:00 UTC (permalink / raw)


bill a �crit dans le message <7a4j3h$64e@drn.newsguy.com>...
>In article <7a4f85$rh1$1@remarQ.com>, "Pat says...
>>
>
>..good stuff snipped..
>
>thanks for the nice review.
>
>Just to compare this to Java, in Java, almost everyone does something
>like this:
>
>import package_name;*
>
>this imports, and at the same time, makes visible all class in
package
>and all public entities in all classes.
>
Nope. Import is equivalent to a "use" clause (makes directly visible),
but is in no way required to get accessibility.
You can use anything without any "import" if you use expanded names.
(which implies that it is almost impossible to know which modules are
required by a given module).
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://perso.wanadoo.fr/adalog






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

* Re: Why both "with" and "use"?
  1999-02-15  0:00     ` Jean-Pierre Rosen
@ 1999-02-15  0:00       ` Ed Falis
  1999-02-16  0:00         ` Jean-Pierre Rosen
  0 siblings, 1 reply; 55+ messages in thread
From: Ed Falis @ 1999-02-15  0:00 UTC (permalink / raw)


On Mon, 15 Feb 1999 10:14:39 +0100, "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:

> Nope. Import is equivalent to a "use" clause (makes directly visible),
> but is in no way required to get accessibility.
> You can use anything without any "import" if you use expanded names.
> (which implies that it is almost impossible to know which modules are
> required by a given module).

Unless you're using a modern IDE, like Visual Age for Java, an Eiffel or Smalltalk IDE, or ObjectAda (and I believe GNAT Ada mode in Emacs?)

The point being, where should the tradeoff be between clutter in the code and tool support?  How much does it make sense to mechanize vs doing a lot of 
bookkeeping in the source code itself?

After using a variety of the tools above in the last year or so, I'm finding I don't miss fully-qualified names and context clauses in environments that don't use them.  In 
fact, it's a relief not having to deal with them as when using Ada bindings to large API sets like the JDK.

- Ed




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00   ` Matthew Heaney
  1999-02-13  0:00     ` bill
  1999-02-13  0:00     ` Tom Moran
@ 1999-02-16  0:00     ` Samuel Mize
  1999-02-17  0:00       ` Jean-Pierre Rosen
                         ` (3 more replies)
  2 siblings, 4 replies; 55+ messages in thread
From: Samuel Mize @ 1999-02-16  0:00 UTC (permalink / raw)


Matthew Heaney <matthew_heaney@acm.org> wrote:
> Corey Minyard <minyard@acm.org> writes:

>> But in most cases, being able to know the package the item is declared
>> in is quite useful.

> Yes, this is true, but not using a use clause isn't the only way to
> effect this goal.  Careful naming conventions make the origin of the
> entity obvious, in spite of the presence of a use clause.

[example snipped]

> These days, I hardly ever don't use a use clause, and I've formed the
> tentative opinion that Ada should have defined the with clause to have
> the semantics of both with and use.

I concur that the use clause is under-used and over-maligned.

I do find it useful sometimes to be able to "with" a package without
"using" it, to control namespaces and prevent annoying collisions.

Overall, I'd just prefer that a "use" statement in a context clause
implied the corresponding "with" statement.

Best,
Sam Mize




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

* Re: Why both "with" and "use"?
  1999-02-13  0:00       ` Matthew Heaney
  1999-02-13  0:00         ` bill
  1999-02-14  0:00         ` Pat Rogers
@ 1999-02-16  0:00         ` Samuel Mize
  2 siblings, 0 replies; 55+ messages in thread
From: Samuel Mize @ 1999-02-16  0:00 UTC (permalink / raw)


Matthew Heaney <matthew_heaney@acm.org> wrote:
> "Pat Rogers" <progers@NOclasswideSPAM.com> writes:

>> A package serves more of a central purpose in Ada 95, especially when
>> it exports a tagged type declaration.
>> 
>> The big difference (or, at least one difference) between Java packages
>> and Ada packages is that the combination of an Ada package and a
>> private type defines an Abstract Data Type.

> I wouldn't quite phrase it that way.  With respect to the declaration of
> a type (and I mean _any_ kind of type, not just ADTs),

You're absolutely right, for types.

I believe that Pat is defining a coding construct, which he calls an
ADT.  This is a free-standing, completely encapsulated type.  It
includes its user-visible values, operations, and exceptions, and
nothing else, and has a syntax-level "wall" around it.

This construct can be directly supported by combining Ada's types and
packages.  I believe Pat is saying that the same is not true of Java's
types and packages.

Heaven knows there are lots of other ways to use types and packages.


> Perhaps I am being pedantic,

I don't think so.


>but I don't regard a package as part of a
> type.  I regard the type as its name, values, and (primitive)
> operations.  The package is just syntactic overhead necessary to
> identify the primitive operations, but the package itself is not part of
> the type.

That's the point.  A type isn't necessarily encapsulated.  Its definition
can be jumbled together with the definitions of othere types, in ways that
create semantic linkages.  Encapsulation is the job of a package.

This is Ada's building-block approach.  If you want your type to be
a completely encapsulated "ADT," slap it into its own package.  If
not, don't.

The package is part of the ADT design construct, but certainly not part
of the type.


> When they give me a bag at the supermarket to hold my groceries, it's the
> groceries that I am interested in, not the bag.  If I were to make a
> list of the things I picked up at the store, I probably wouldn't include
> the bag in that list.

To strain the analogy a little, suppose you got groceries for three
people.  You might put them in separate bags, for ease of handling.
From that viewpoint, the list might be "my groceries, Pat's groceries,
and Sam's groceries."  You would list neither the bags nor the contents
at that level of abstraction.

Best,
Sam Mize




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

* Re: Why both "with" and "use"?
  1999-02-15  0:00       ` Ed Falis
@ 1999-02-16  0:00         ` Jean-Pierre Rosen
  0 siblings, 0 replies; 55+ messages in thread
From: Jean-Pierre Rosen @ 1999-02-16  0:00 UTC (permalink / raw)


Ed Falis a �crit dans le message <1103_919091637@DZOG-CHEN>...
>On Mon, 15 Feb 1999 10:14:39 +0100, "Jean-Pierre Rosen"
<rosen.adalog@wanadoo.fr> wrote:
>
>> Nope. Import is equivalent to a "use" clause (makes directly
visible),
>> but is in no way required to get accessibility.
>> You can use anything without any "import" if you use expanded
names.
>> (which implies that it is almost impossible to know which modules
are
>> required by a given module).
>
>Unless you're using a modern IDE, like Visual Age for Java, an Eiffel
or Smalltalk IDE, or ObjectAda (and I believe GNAT Ada mode in Emacs?)
>
>The point being, where should the tradeoff be between clutter in the
code and tool support?  How much does it make sense to mechanize vs
doing a lot of
>bookkeeping in the source code itself?
>
>After using a variety of the tools above in the last year or so, I'm
finding I don't miss fully-qualified names and context clauses in
environments that don't use them.  In
>fact, it's a relief not having to deal with them as when using Ada
bindings to large API sets like the JDK.
>
I agree with you (I'm a known supporter of the use clause), but I
think you misunderstood my remark.

I was stating that in Java, the whole world is "withed" (and this can
include modules on a server on an island in the Pacific).
To know what is really used, import clauses are not sufficient, you
also need to check all fully qualified names. And if you rewrote your
own dynamic loader, I don't see how you can know what is really used !
(BTW, this implies that configuration management in Java is a
world-wide issue !!)
I doubt ObjectAda provides this feature, since (fortunately) we have
"with" clauses in Ada !
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://perso.wanadoo.fr/adalog






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

* Re: Why both "with" and "use"?
  1999-02-16  0:00     ` Samuel Mize
  1999-02-17  0:00       ` Jean-Pierre Rosen
@ 1999-02-17  0:00       ` Matthew Heaney
  1999-02-17  0:00       ` dennison
  1999-02-17  0:00       ` Jean-Pierre Rosen
  3 siblings, 0 replies; 55+ messages in thread
From: Matthew Heaney @ 1999-02-17  0:00 UTC (permalink / raw)


Samuel Mize <smize@imagin.net> writes:

> Overall, I'd just prefer that a "use" statement in a context clause
> implied the corresponding "with" statement.

Yes!  That's what I think too.




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

* Re: Why both "with" and "use"?
  1999-02-16  0:00     ` Samuel Mize
  1999-02-17  0:00       ` Jean-Pierre Rosen
  1999-02-17  0:00       ` Matthew Heaney
@ 1999-02-17  0:00       ` dennison
  1999-02-17  0:00         ` Nick Roberts
  1999-02-17  0:00         ` Samuel Mize
  1999-02-17  0:00       ` Jean-Pierre Rosen
  3 siblings, 2 replies; 55+ messages in thread
From: dennison @ 1999-02-17  0:00 UTC (permalink / raw)


In article <7acj53$1vu@news3.newsguy.com>,
  Samuel Mize <smize@imagin.net> wrote:

> Overall, I'd just prefer that a "use" statement in a context clause
> implied the corresponding "with" statement.

Hmmm. Would a "use type" clause also imply a "with"? Would a "use" for a child
imply a "with" of its parents?

T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-17  0:00       ` dennison
@ 1999-02-17  0:00         ` Nick Roberts
  1999-02-17  0:00         ` Samuel Mize
  1 sibling, 0 replies; 55+ messages in thread
From: Nick Roberts @ 1999-02-17  0:00 UTC (permalink / raw)


dennison@telepath.com wrote in message <7aejjv$tj$1@nnrp1.dejanews.com>...
[...]
|Hmmm. Would a "use type" clause also imply a "with"? Would a "use" for a
child
|imply a "with" of its parents?


No reason why not. After all, a "with" of a child implies a "with" of its
parent (all its ancestors, in fact).

-------------------------------------------
Nick Roberts
-------------------------------------------







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

* Re: Why both "with" and "use"?
  1999-02-17  0:00       ` dennison
  1999-02-17  0:00         ` Nick Roberts
@ 1999-02-17  0:00         ` Samuel Mize
  1 sibling, 0 replies; 55+ messages in thread
From: Samuel Mize @ 1999-02-17  0:00 UTC (permalink / raw)


dennison@telepath.com wrote:
>   Samuel Mize <smize@imagin.net> wrote:
>
>> Overall, I'd just prefer that a "use" statement in a context clause
>> implied the corresponding "with" statement.
>
> Hmmm. Would a "use type" clause also imply a "with"? Would a "use" for
>a child
> imply a "with" of its parents?

I reckon so, but I haven't studied the question in detail.  Are you aware
of problems with that?  (Except that the compilers today don't DO it,
of course...)

Best,
Sam Mize

--
Samuel Mize -- smize@imagin.net (home email) -- Team Ada
Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam





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

* Re: Why both "with" and "use"?
  1999-02-16  0:00     ` Samuel Mize
@ 1999-02-17  0:00       ` Jean-Pierre Rosen
  1999-02-18  0:00         ` dennison
  1999-02-18  0:00         ` robert_dewar
  1999-02-17  0:00       ` Matthew Heaney
                         ` (2 subsequent siblings)
  3 siblings, 2 replies; 55+ messages in thread
From: Jean-Pierre Rosen @ 1999-02-17  0:00 UTC (permalink / raw)


Samuel Mize a �crit dans le message <7acj53$1vu@news3.newsguy.com>...
>I do find it useful sometimes to be able to "with" a package without
>"using" it, to control namespaces and prevent annoying collisions.
>
All this discussion (and most of the reasons why some people do not
like the "use") comes from the fact that few people realize that the
use is not necessarily after the with! (and this comes from the
unfortunate examples in RM83, where *all* "use" were with "with").

My personal religion is to apply the use to the smallest region where
it is necessary. If I need a package in a procedure, I put a use in
the procedure. More precisely: if I need it for some declarations, I
put it at the top of the declarative part. If I need it only for
statements, I put it just before "begin", unless I need it only for
operators in which case I use a "use type". In some cases (like
needing Ada.Exceptions in an exception handler), I put a declare block
just for the use clause.
This provides me with very fine tracking of package usage. And since I
almost never use full names, the compiler will tell me if I forget to
"document" this way my usage of packages.

Actually, I wonder how people who always use expanded names can know
precisely how packages are used... (Point of information: I hate cross
checking with X-refs ;-).
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://perso.wanadoo.fr/adalog






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

* Re: Why both "with" and "use"?
  1999-02-16  0:00     ` Samuel Mize
                         ` (2 preceding siblings ...)
  1999-02-17  0:00       ` dennison
@ 1999-02-17  0:00       ` Jean-Pierre Rosen
  3 siblings, 0 replies; 55+ messages in thread
From: Jean-Pierre Rosen @ 1999-02-17  0:00 UTC (permalink / raw)


Samuel Mize a �crit dans le message <7acj53$1vu@news3.newsguy.com>...
>I do find it useful sometimes to be able to "with" a package without
>"using" it, to control namespaces and prevent annoying collisions.
>
All this discussion (and most of the reasons why some people do not
like the "use") comes from the fact that few people realize that the
use is not necessarily after the with! (and this comes from the
unfortunate examples in RM83, where *all* "use" were with "with").

My personal religion is to apply the use to the smallest region where
it is necessary. If I need a package in a procedure, I put a use in
the procedure. More precisely: if I need it for some declarations, I
put it at the top of the declarative part. If I need it only for
statements, I put it just before "begin", unless I need it only for
operators in which case I use a "use type". In some cases (like
needing Ada.Exceptions in an exception handler), I put a declare block
just for the use clause.
This provides me with very fine tracking of package usage. And since I
almost never use full names, the compiler will tell me if I forget to
"document" this way my usage of packages.

Actually, I wonder how people who always use expanded names can know
precisely how packages are used... (Point of information: I hate cross
checking with X-refs ;-).
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://perso.wanadoo.fr/adalog






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

* Re: Why both "with" and "use"?
  1999-02-17  0:00       ` Jean-Pierre Rosen
@ 1999-02-18  0:00         ` dennison
  1999-02-18  0:00           ` robert_dewar
  1999-02-19  0:00           ` Matthew Heaney
  1999-02-18  0:00         ` robert_dewar
  1 sibling, 2 replies; 55+ messages in thread
From: dennison @ 1999-02-18  0:00 UTC (permalink / raw)


In article <7af68r$52o$1@platane.wanadoo.fr>,
  "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:
> My personal religion is to apply the use to the smallest region where
> it is necessary. If I need a package in a procedure, I put a use in
...
> This provides me with very fine tracking of package usage. And since I
> almost never use full names, the compiler will tell me if I forget to
> "document" this way my usage of packages.
>
> Actually, I wonder how people who always use expanded names can know
> precisely how packages are used... (Point of information: I hate cross
> checking with X-refs ;-).

A good point. But since named notation isn't used, you can't clearly see what
in that scope is from what package. Without resorting to a cross-referencing
tool you don't really know *how* the package is used, just roughly *where*.

With named notation a simple textual search through the source will suffice.
No fancy tool required. T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-18  0:00           ` Jean-Pierre Rosen
@ 1999-02-18  0:00             ` robert_dewar
  1999-02-19  0:00               ` Jean-Pierre Rosen
  0 siblings, 1 reply; 55+ messages in thread
From: robert_dewar @ 1999-02-18  0:00 UTC (permalink / raw)


In article <7ah3te$g6p$1@platane.wanadoo.fr>,
  "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:
> Of course, this is an abuse and common sense applies. My
> example was rather:

> exception
>    when Occur : others =>
>       declare
>           use Ada.Exceptions;
>       begin
>            Put_Line ("Oops" & Exception_Name (Occur));
>            Raise_Exception (My_Exception'Identity,
>                  Message => Exception_Message (Occur));
>       end;
>
> Here, I wouldn't like a use clause applying to the whole
> subprogram when I really need it only in the exception
> part.

I actually am just as happy to take this as an example of
unnecessary obfuscation. Here we have a package whose names
have been designed to be conveniently used with a USE
clause. THere is really no reason to write
Ada.Exceptions.Exception_Message, instead of just
Exception_Message.

Now the normal approach of simply adding the use clause
to the context clause puts the use clause out of the way
and takes only three tokens.

JPR's usage above takes 8 tokens, even assuming it is only
used once in a unit (8*N if it is used N times), and worse,
inteferes with the clarity of the code by introducing
extraneous junk which serves no real purpose at this point
in the code.


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-18  0:00         ` dennison
@ 1999-02-18  0:00           ` robert_dewar
  1999-02-19  0:00             ` bourguet
                               ` (2 more replies)
  1999-02-19  0:00           ` Matthew Heaney
  1 sibling, 3 replies; 55+ messages in thread
From: robert_dewar @ 1999-02-18  0:00 UTC (permalink / raw)


In article <7ahq7p$s6k$1@nnrp1.dejanews.com>,
  dennison@telepath.com wrote:
> A good point. But since named notation isn't used, you
> can't clearly see what in that scope is from what
> package. Without resorting to a cross-referencing
> tool you don't really know *how* the package is used,
> just roughly *where*.

"resorting" sounds like it must be hard work, but this need
not be the case, if you are using GNAT and EMACS, this is
a very easy operation


> With named notation a simple textual search through the
> source will suffice.

Not always, here is a little puzzle for the folks out in
CLA-land:

A unit contains:

      x := Mumble (Q);

a search of the unit in which this statement appears shows
no other trace of the string Mumble, and no dreaded use
clauses.

How could this be?


> No fancy tool required. T.E.D.
>
> -----------== Posted via Deja News, The Discussion
Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or
Start Your Own
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-17  0:00       ` Jean-Pierre Rosen
  1999-02-18  0:00         ` dennison
@ 1999-02-18  0:00         ` robert_dewar
  1999-02-18  0:00           ` Jean-Pierre Rosen
  1 sibling, 1 reply; 55+ messages in thread
From: robert_dewar @ 1999-02-18  0:00 UTC (permalink / raw)


In article <7af68r$52o$1@platane.wanadoo.fr>,
  "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:
> My personal religion is to apply the use to the smallest
> region where it is necessary.

I very much dislike this style, I think this kind of very
local use obfuscates the code, especially if you go so far
as to create blocks just for the purpose of including a use
clause. I would hate to see

    declare
       use Text_IO;
    begin
       Put (A);
       Put (B);
       Put_Line (C);
    end;

I don't see that as helpful.

This does not mean of course that local use is always a bad
idea, but I am suspicious of any "religeon" in this area.
Better to have a completely non-religeous viewpoint, and
use whatever makes best sense in each particular situation.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-18  0:00         ` robert_dewar
@ 1999-02-18  0:00           ` Jean-Pierre Rosen
  1999-02-18  0:00             ` robert_dewar
  0 siblings, 1 reply; 55+ messages in thread
From: Jean-Pierre Rosen @ 1999-02-18  0:00 UTC (permalink / raw)



robert_dewar@my-dejanews.com a �crit dans le message
<7afue4$8ed$1@nnrp1.dejanews.com>...
>In article <7af68r$52o$1@platane.wanadoo.fr>,
>  "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:
>> My personal religion is to apply the use to the smallest
>> region where it is necessary.
>
>I very much dislike this style, I think this kind of very
>local use obfuscates the code, especially if you go so far
>as to create blocks just for the purpose of including a use
>clause. I would hate to see
>
>    declare
>       use Text_IO;
>    begin
>       Put (A);
>       Put (B);
>       Put_Line (C);
>    end;
>
>I don't see that as helpful.
Of course, this is an abuse and common sense applies. My example was
rather:
exception
   when Occur : others =>
      declare
          use Ada.Exceptions;
      begin
           Put_Line ("Oops" & Exception_Name (Occur));
           Raise_Exception (My_Exception'Identity, Message =>
Exception_Message (Occur));
      end;

Here, I wouldn't like a use clause applying to the whole subprogram
when I really need it only in the exception part.

>This does not mean of course that local use is always a bad
>idea, but I am suspicious of any "religeon" in this area.
>Better to have a completely non-religeous viewpoint, and
>use whatever makes best sense in each particular situation.
OK, I should have put a IMHO instead - some people are so religious
about religions :-)
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://perso.wanadoo.fr/adalog






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

* Re: Why both "with" and "use"?
  1999-02-18  0:00           ` robert_dewar
@ 1999-02-19  0:00             ` bourguet
  1999-02-19  0:00               ` robert_dewar
  1999-02-19  0:00             ` dennison
  1999-02-19  0:00             ` Robert I. Eachus
  2 siblings, 1 reply; 55+ messages in thread
From: bourguet @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7ai7p1$8kp$1@nnrp1.dejanews.com>,
  robert_dewar@my-dejanews.com wrote:
> Not always, here is a little puzzle for the folks out in
> CLA-land:
>
> A unit contains:
>
>       x := Mumble (Q);
>
> a search of the unit in which this statement appears shows
> no other trace of the string Mumble, and no dreaded use
> clauses.
>
> How could this be?

This unit is separated. Or is there another possibility?

-- Jean-Marc

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-19  0:00             ` bourguet
@ 1999-02-19  0:00               ` robert_dewar
  0 siblings, 0 replies; 55+ messages in thread
From: robert_dewar @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7ajc92$78n$1@nnrp1.dejanews.com>,
  bourguet@my-dejanews.com wrote:
> In article <7ai7p1$8kp$1@nnrp1.dejanews.com>,
>   robert_dewar@my-dejanews.com wrote:
> > Not always, here is a little puzzle for the folks out
> > in
> > CLA-land:
> >
> > A unit contains:
> >
> >       x := Mumble (Q);
> >
> > a search of the unit in which this statement appears
> > shows
> > no other trace of the string Mumble, and no dreaded use
> > clauses.
> >
> > How could this be?
>
> This unit is separated. Or is there another possibility?


Right, of course this can happen with separate or child
units, so let's make another criterion. The unit is NOT
a child unit, and is NOT a separate unit :-)


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-18  0:00           ` robert_dewar
  1999-02-19  0:00             ` bourguet
@ 1999-02-19  0:00             ` dennison
  1999-02-19  0:00             ` Robert I. Eachus
  2 siblings, 0 replies; 55+ messages in thread
From: dennison @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7ai7p1$8kp$1@nnrp1.dejanews.com>,
  robert_dewar@my-dejanews.com wrote:
> In article <7ahq7p$s6k$1@nnrp1.dejanews.com>,
>   dennison@telepath.com wrote:
> > With named notation a simple textual search through the
> > source will suffice.
>
> Not always, here is a little puzzle for the folks out in
> CLA-land:
>
> A unit contains:
>
>       x := Mumble (Q);
>
> a search of the unit in which this statement appears shows
> no other trace of the string Mumble, and no dreaded use
> clauses.
>
> How could this be?

Ahhh, yes. Its probably declared in a parent package. I'd convienently
fogotten that new twist. Unfortunately, it does come up a lot.

T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-18  0:00             ` robert_dewar
@ 1999-02-19  0:00               ` Jean-Pierre Rosen
  0 siblings, 0 replies; 55+ messages in thread
From: Jean-Pierre Rosen @ 1999-02-19  0:00 UTC (permalink / raw)



robert_dewar@my-dejanews.com a �crit dans le message
<7ai5br$6g3$1@nnrp1.dejanews.com>...
>In article <7ah3te$g6p$1@platane.wanadoo.fr>,
>  "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:
>JPR's usage above takes 8 tokens, even assuming it is only
>used once in a unit (8*N if it is used N times), and worse,
>inteferes with the clarity of the code by introducing
>extraneous junk which serves no real purpose at this point
>in the code.
Well, if you count by the token, you really should be using APL...
(sorry, couldn't resist).

In my view, the "real purpose" it serves is documenting for the reader
the places where a package is used.
If I feel that a package is used everywhere in a unit, I do put a
global use clause. If I with a package for a specific purpose in a
specific part of my code, I put the use around that part to document
that fact. "Part" maybe as small as a couple of instructions as above,
it's generally one procedure, it can be a lot more.
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://perso.wanadoo.fr/adalog






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

* Re: Why both "with" and "use"?
  1999-02-19  0:00           ` Matthew Heaney
@ 1999-02-19  0:00             ` dennison
  1999-02-19  0:00               ` robert_dewar
  0 siblings, 1 reply; 55+ messages in thread
From: dennison @ 1999-02-19  0:00 UTC (permalink / raw)


In article <m3ogmr40bj.fsf@mheaney.ni.net>,
  Matthew Heaney <matthew_heaney@acm.org> wrote:
> dennison@telepath.com writes:
>
> > In article <7af68r$52o$1@platane.wanadoo.fr>,
> >   "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:
> > > Actually, I wonder how people who always use expanded names can know
> > > precisely how packages are used... (Point of information: I hate cross
> > > checking with X-refs ;-).
> >
> > A good point. But since named notation isn't used, you can't clearly see
what
> > in that scope is from what package. Without resorting to a cross-referencing
> > tool you don't really know *how* the package is used, just roughly *where*.
> >
> > With named notation a simple textual search through the source will suffice.
> > No fancy tool required.
>
> True, but no fancy tool is required if you use certain naming
> conventions.

You mean if *everyone* uses certain naming conventions. I have no control over
the naming conventions the autors of the LRM and reusable components used.

Anyway, doesn't it seem silly to have a standard where one repeats the package
name in every identifier so that dot notation doesn't have to be used? Is the
'_' character somehow superior to the '.'?

Your example is particularly appropriate, because
Ada.Strings.Unbounded.Unbounded_String looks like it was created by the
department of redundancy department. :-)

T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-18  0:00           ` robert_dewar
  1999-02-19  0:00             ` bourguet
  1999-02-19  0:00             ` dennison
@ 1999-02-19  0:00             ` Robert I. Eachus
  1999-02-19  0:00               ` robert_dewar
  1999-02-19  0:00               ` Brian Hanson
  2 siblings, 2 replies; 55+ messages in thread
From: Robert I. Eachus @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7ai7p1$8kp$1@nnrp1.dejanews.com> robert_dewar@my-dejanews.com writes:

  > Not always, here is a little puzzle for the folks out in CLA-land:
  > A unit contains:
  >	 x := Mumble (Q);
  > a search of the unit in which this statement appears shows
  > no other trace of the string Mumble, and no dreaded use clauses.
  > How could this be?

   Easy:

package ADT is 
   type Froz is new Integer;
   procedure Mumble(F: in out Froz);
end ADT;

package body ADT is
   procedure Mumble(F: in out Froz) is
   begin F := F + 1; end Mumble;
end ADT;

with ADT;
procedure Main is
   type Frozbaz is new ADT.Froz;
   X: Frozbaz := 0;
begin
   Mumble(X);
end Main;
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

* Re: Why both "with" and "use"?
  1999-02-19  0:00             ` dennison
@ 1999-02-19  0:00               ` robert_dewar
  1999-02-19  0:00                 ` Ada multiple string personalities. why so many? mike
  1999-02-19  0:00                 ` Why both "with" and "use"? dennison
  0 siblings, 2 replies; 55+ messages in thread
From: robert_dewar @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7ak471$rt9$1@nnrp1.dejanews.com>,
  dennison@telepath.com wrote:
>> Your example is particularly appropriate, because
> Ada.Strings.Unbounded.Unbounded_String looks like it
> was created by the department of redundancy department.
> :-)

Not at all, it was created with the intention that
a USE clause would be used on this package, and in
that case Unbounded_String is quite a reasonable name.

If it was named simply String, that would create a nasty
clash with the type in Standard, and would be much
less convenient, because then we would write
Ada.Strings.Unbounded.String, which is still a mouthful!

Furthermore, we really do not typically want to have
to preface every routine in this package by Unbounded,

  Unbounded.Head (Unbounded.To_String ("abc"), ....

seems plain annoying to me!

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-19  0:00               ` robert_dewar
  1999-02-19  0:00                 ` Ada multiple string personalities. why so many? mike
@ 1999-02-19  0:00                 ` dennison
  1999-02-19  0:00                   ` robert_dewar
  1 sibling, 1 reply; 55+ messages in thread
From: dennison @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7akabo$1uk$1@nnrp1.dejanews.com>,
  robert_dewar@my-dejanews.com wrote:

>
> Furthermore, we really do not typically want to have
> to preface every routine in this package by Unbounded,
>
>   Unbounded.Head (Unbounded.To_String ("abc"), ....
>
> seems plain annoying to me!

...until you try programming with bounded strings too.

T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-19  0:00             ` Robert I. Eachus
@ 1999-02-19  0:00               ` robert_dewar
  1999-02-23  0:00                 ` Robert I. Eachus
  1999-02-19  0:00               ` Brian Hanson
  1 sibling, 1 reply; 55+ messages in thread
From: robert_dewar @ 1999-02-19  0:00 UTC (permalink / raw)


In article <EACHUS.99Feb19122049@spectre.mitre.org>,
  eachus@spectre.mitre.org (Robert I. Eachus) wrote:
>    Easy:
>
> package ADT is
>    type Froz is new Integer;
>    procedure Mumble(F: in out Froz);
> end ADT;
>
> package body ADT is
>    procedure Mumble(F: in out Froz) is
>    begin F := F + 1; end Mumble;
> end ADT;
>
> with ADT;
> procedure Main is
>    type Frozbaz is new ADT.Froz;
>    X: Frozbaz := 0;
> begin
>    Mumble(X);
> end Main;


Well yes, especially easy, since Robert Eachus and I have
discussed this particular case many times (Robert, you
should really have let people who have NOT thought about
this before think a little longer, too bad you jumped in,
not really fair :-)

Anyway, that should be instructive, most people find this
a surprise when they first encounter it.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-19  0:00               ` Brian Hanson
@ 1999-02-19  0:00                 ` robert_dewar
  0 siblings, 0 replies; 55+ messages in thread
From: robert_dewar @ 1999-02-19  0:00 UTC (permalink / raw)


In article <36CDA87B.E0F36D27@lawson.com>,
  Brian Hanson <brian.hanson@lawson.com> wrote:
> Slightly less obvious.
>
> package Rd is
>    type T is new Integer;
>    function Mumble(V: T) return Integer;
> end Rd;
>
> with Rd;
> procedure main is
>    type Z is new Rd.T;
>    Vi: integer;
> begin
>    vi := Mumble(25);
> end;

Even less obvious is the case where you see only a subtype
and cannot even see the original type, but you can still
derive and get the local operations, i.e. Mumble may not
even be in any of the things you with!

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Ada multiple string personalities. why so many?
  1999-02-19  0:00               ` robert_dewar
@ 1999-02-19  0:00                 ` mike
  1999-02-19  0:00                   ` robert_dewar
  1999-02-19  0:00                   ` Tom Moran
  1999-02-19  0:00                 ` Why both "with" and "use"? dennison
  1 sibling, 2 replies; 55+ messages in thread
From: mike @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7akabo$1uk$1@nnrp1.dejanews.com>, robert_dewar@my-dejanews.com
says...
 
>If it was named simply String, that would create a nasty
>clash with the type in Standard, and would be much
>less convenient, because then we would write
>Ada.Strings.Unbounded.String, which is still a mouthful!
>
 
Why did Ada had to have 3 types for a string? the standard 
string, the bounded string, and the unbounded string.

In C++, there is only one <string> header that defines
one string container template thing that holds 
character things. just one.

So, a C++ string is like that of Ada's ada.strings.unbounded.string.

That is all what is really needed, no?. It might not be the most
efficient, but it seems better to have one general type that does
eveything that 3 different types one can do a litle more with.

Mike




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

* Re: Why both "with" and "use"?
  1999-02-19  0:00                 ` Why both "with" and "use"? dennison
@ 1999-02-19  0:00                   ` robert_dewar
  0 siblings, 0 replies; 55+ messages in thread
From: robert_dewar @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7akfni$6ua$1@nnrp1.dejanews.com>,
  dennison@telepath.com wrote:
> In article <7akabo$1uk$1@nnrp1.dejanews.com>,
>   robert_dewar@my-dejanews.com wrote:
>
> >
> > Furthermore, we really do not typically want to have
> > to preface every routine in this package by Unbounded,
> >
> >   Unbounded.Head (Unbounded.To_String ("abc"), ....
> >
> > seems plain annoying to me!
>
> ...until you try programming with bounded strings too.


Not at all!!

Your declarations in this case will say Bounded_String or
Unbounded_String and then of course you get the right
Trim. That is what overloading is all about, and why it
is useful.

Surely you do not get upset that "+" means different things
depending on which type it is applied to???

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Ada multiple string personalities. why so many?
  1999-02-19  0:00                 ` Ada multiple string personalities. why so many? mike
  1999-02-19  0:00                   ` robert_dewar
@ 1999-02-19  0:00                   ` Tom Moran
  1999-02-19  0:00                     ` Mike Silva
  1 sibling, 1 reply; 55+ messages in thread
From: Tom Moran @ 1999-02-19  0:00 UTC (permalink / raw)


>In C++, there is only one <string> header that defines
>one string container template thing that holds 
>character things. just one.

>So, a C++ string is like that of Ada's ada.strings.unbounded.string.
  There is only one string in Ada 95, Unbounded String, just like C++
(Just forget any rumors you've heard or texts you've read about fixed
or limited length strings ;)




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

* Re: Ada multiple string personalities. why so many?
  1999-02-19  0:00                   ` Tom Moran
@ 1999-02-19  0:00                     ` Mike Silva
  1999-02-22  0:00                       ` Brian Hanson
  0 siblings, 1 reply; 55+ messages in thread
From: Mike Silva @ 1999-02-19  0:00 UTC (permalink / raw)



Tom Moran wrote in message <36cdddc8.12285254@news.pacbell.net>...
>>In C++, there is only one <string> header that defines
>>one string container template thing that holds
>>character things. just one.
>
>>So, a C++ string is like that of Ada's ada.strings.unbounded.string.

>  There is only one string in Ada 95, Unbounded String, just like C++
>(Just forget any rumors you've heard or texts you've read about fixed
>or limited length strings ;)

Really?  I'm just an Ada novice, but I've programmed lots of embedded
systems and I can't imagine using unbounded strings (in whatever language)
where I would need strings in such systems.

Mike







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

* Re: Ada multiple string personalities. why so many?
  1999-02-19  0:00                 ` Ada multiple string personalities. why so many? mike
@ 1999-02-19  0:00                   ` robert_dewar
  1999-02-19  0:00                   ` Tom Moran
  1 sibling, 0 replies; 55+ messages in thread
From: robert_dewar @ 1999-02-19  0:00 UTC (permalink / raw)


In article <7akgld$5ue@drn.newsguy.com>,
  mike@eexz wrote:
> In article <7akabo$1uk$1@nnrp1.dejanews.com>,
robert_dewar@my-dejanews.com
> Why did Ada had to have 3 types for a string? the
> standard  string, the bounded string, and the unbounded
> string.
>
> In C++, there is only one <string> header that defines
> one string container template thing that holds
> character things. just one.
>
> So, a C++ string is like that of Ada's
> ada.strings.unbounded.string.
>
> That is all what is really needed, no?.

In short, no!

There are distinct needs here and the three types meet
these distinct needs. Obviously for example you could
not use unbounded strings in an embedded application where
dynamic allocation was not permitted. Equally obviously,
C++ has a big hole in such environments compared to Ada
if it does not provide the important functionality of
Bounded Strings (well of course -- big hole -- you can
of course program this functionality yourself).

> It might not be the most
> efficient, but it seems better to have one general type
> that does everything that 3 different types one can do a
> litle more with.


If efficiency is of no concern to you, I suggest you stop
fiddling with low level languages like Ada and C++ and
instead use very high level languages like Prolog, or
Haskell, you will find that indeed it makes programming
simpler :-)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Why both "with" and "use"?
  1999-02-18  0:00         ` dennison
  1999-02-18  0:00           ` robert_dewar
@ 1999-02-19  0:00           ` Matthew Heaney
  1999-02-19  0:00             ` dennison
  1 sibling, 1 reply; 55+ messages in thread
From: Matthew Heaney @ 1999-02-19  0:00 UTC (permalink / raw)


dennison@telepath.com writes:

> In article <7af68r$52o$1@platane.wanadoo.fr>,
>   "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:
> > Actually, I wonder how people who always use expanded names can know
> > precisely how packages are used... (Point of information: I hate cross
> > checking with X-refs ;-).
> 
> A good point. But since named notation isn't used, you can't clearly see what
> in that scope is from what package. Without resorting to a cross-referencing
> tool you don't really know *how* the package is used, just roughly *where*.
> 
> With named notation a simple textual search through the source will suffice.
> No fancy tool required. T.E.D.

True, but no fancy tool is required if you use certain naming
conventions.

If I see this:

...
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

package body P is
...

   procedure Op (...) is

     Text : Unbounded_String;
   begin
    

then it doesn't require much imagination to realize that type
Unbounded_String came from package Ada.Strings.Unbounded.

Ditto for operations.  Since most of the time operations that take a
type as a parameter or return value are declared in the same package in
which the type is declared, then that's where the operation is too.

Expanded name notation and package renaming are used far more often than
they need to be.  Better to use these techniques when an operation or
type is declared in an unobvious place.









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

* Re: Why both "with" and "use"?
  1999-02-19  0:00             ` Robert I. Eachus
  1999-02-19  0:00               ` robert_dewar
@ 1999-02-19  0:00               ` Brian Hanson
  1999-02-19  0:00                 ` robert_dewar
  1 sibling, 1 reply; 55+ messages in thread
From: Brian Hanson @ 1999-02-19  0:00 UTC (permalink / raw)


Slightly less obvious.

package Rd is
   type T is new Integer;
   function Mumble(V: T) return Integer;
end Rd;

with Rd;
procedure main is
   type Z is new Rd.T;
   Vi: integer;
begin
   vi := Mumble(25);
end;

"Robert I. Eachus" wrote:

> In article <7ai7p1$8kp$1@nnrp1.dejanews.com> robert_dewar@my-dejanews.com writes:
>
>   > Not always, here is a little puzzle for the folks out in CLA-land:
>   > A unit contains:
>   >      x := Mumble (Q);
>   > a search of the unit in which this statement appears shows
>   > no other trace of the string Mumble, and no dreaded use clauses.
>   > How could this be?
>
>    Easy:
>
> package ADT is
>    type Froz is new Integer;
>    procedure Mumble(F: in out Froz);
> end ADT;
>
> package body ADT is
>    procedure Mumble(F: in out Froz) is
>    begin F := F + 1; end Mumble;
> end ADT;
>
> with ADT;
> procedure Main is
>    type Frozbaz is new ADT.Froz;
>    X: Frozbaz := 0;
> begin
>    Mumble(X);
> end Main;
> --
>
>                                         Robert I. Eachus
>
> with Standard_Disclaimer;
> use  Standard_Disclaimer;
> function Message (Text: in Clever_Ideas) return Better_Ideas is...





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

* Re: Ada multiple string personalities. why so many?
  1999-02-19  0:00                     ` Mike Silva
@ 1999-02-22  0:00                       ` Brian Hanson
  0 siblings, 0 replies; 55+ messages in thread
From: Brian Hanson @ 1999-02-22  0:00 UTC (permalink / raw)




Mike Silva wrote:

> Tom Moran wrote in message <36cdddc8.12285254@news.pacbell.net>...
> >>In C++, there is only one <string> header that defines
> >>one string container template thing that holds
> >>character things. just one.
> >
> >>So, a C++ string is like that of Ada's ada.strings.unbounded.string.
>
> >  There is only one string in Ada 95, Unbounded String, just like C++
> >(Just forget any rumors you've heard or texts you've read about fixed
> >or limited length strings ;)
>
> Really?  I'm just an Ada novice, but I've programmed lots of embedded
> systems and I can't imagine using unbounded strings (in whatever language)
> where I would need strings in such systems.

Shhhhhhh...  Yes they do exist but there is no need to disturb Mike with these

obviously useless bounded and fixed length strings.





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

* Re: Why both "with" and "use"?
  1999-02-19  0:00               ` robert_dewar
@ 1999-02-23  0:00                 ` Robert I. Eachus
  0 siblings, 0 replies; 55+ messages in thread
From: Robert I. Eachus @ 1999-02-23  0:00 UTC (permalink / raw)


In article <7akgvr$82k$1@nnrp1.dejanews.com> robert_dewar@my-dejanews.com writes:

 > Well yes, especially easy, since Robert Eachus and I have
 > discussed this particular case many times (Robert, you
 > should really have let people who have NOT thought about
 > this before think a little longer, too bad you jumped in,
 > not really fair :-)

  If you hadn't posted on a Thursday, I would have waited longer.  But
our church was moving into a new building this weekend, so I didn't
expect to have time to log in from home.  (Or for that matter from the
church.  The phones lines weren't moved until late yesterday, so I
could do most of the work of setting up the computers, but not check
net access.)

 > Anyway, that should be instructive, most people find this
 > a surprise when they first encounter it.

  The classic, "It's not a bug it is a feature!"  Once you understand
it, you understand why any alternative would be worse, and it is one
of those language features you try to avoid the dark corners of.
Another is that overloading subprograms is a wonderful feature, as is
overriding.  But hiding a subprogram, or worse yet creating a
subprogram that can't be called is bad...  What's wrong with this
picture?

  with Ada.Text_IO;
  procedure Puzzle is
     procedure My_Put(S: String; N: Integer := 1) is 
     begin 
       Ada.Text_IO.New_Line(Ada.Text_IO.Count(N));
       Ada.Text_IO.Put(S);
     end My_Put;
     procedure My_Put(S: String) is 
     begin Ada.Text_IO.Put(S); end My_Put;
  begin
     My_Put("Hello World!");
  end Puzzle;

  Once you see why this won't compile, you think that it is no big
deal.  But it is!  If during maintenance a parameter with a default is
added to an outer declaration, it can cause working code not to
compile.  The best solution is to always avoid hiding in Ada--it
doesn't help much, and can be a later maintenance problem.
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

end of thread, other threads:[~1999-02-23  0:00 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-13  0:00 Why both "with" and "use"? Mike Silva
1999-02-13  0:00 ` Corey Minyard
1999-02-13  0:00   ` Matthew Heaney
1999-02-13  0:00     ` bill
1999-02-14  0:00       ` dewar
1999-02-14  0:00       ` dewar
1999-02-14  0:00       ` Matthew Heaney
1999-02-13  0:00     ` Tom Moran
1999-02-14  0:00       ` Matthew Heaney
1999-02-16  0:00     ` Samuel Mize
1999-02-17  0:00       ` Jean-Pierre Rosen
1999-02-18  0:00         ` dennison
1999-02-18  0:00           ` robert_dewar
1999-02-19  0:00             ` bourguet
1999-02-19  0:00               ` robert_dewar
1999-02-19  0:00             ` dennison
1999-02-19  0:00             ` Robert I. Eachus
1999-02-19  0:00               ` robert_dewar
1999-02-23  0:00                 ` Robert I. Eachus
1999-02-19  0:00               ` Brian Hanson
1999-02-19  0:00                 ` robert_dewar
1999-02-19  0:00           ` Matthew Heaney
1999-02-19  0:00             ` dennison
1999-02-19  0:00               ` robert_dewar
1999-02-19  0:00                 ` Ada multiple string personalities. why so many? mike
1999-02-19  0:00                   ` robert_dewar
1999-02-19  0:00                   ` Tom Moran
1999-02-19  0:00                     ` Mike Silva
1999-02-22  0:00                       ` Brian Hanson
1999-02-19  0:00                 ` Why both "with" and "use"? dennison
1999-02-19  0:00                   ` robert_dewar
1999-02-18  0:00         ` robert_dewar
1999-02-18  0:00           ` Jean-Pierre Rosen
1999-02-18  0:00             ` robert_dewar
1999-02-19  0:00               ` Jean-Pierre Rosen
1999-02-17  0:00       ` Matthew Heaney
1999-02-17  0:00       ` dennison
1999-02-17  0:00         ` Nick Roberts
1999-02-17  0:00         ` Samuel Mize
1999-02-17  0:00       ` Jean-Pierre Rosen
1999-02-13  0:00   ` mike
1999-02-13  0:00 ` Pat Rogers
1999-02-13  0:00   ` bill
1999-02-13  0:00     ` Pat Rogers
1999-02-13  0:00       ` Matthew Heaney
1999-02-13  0:00         ` bill
1999-02-14  0:00         ` Pat Rogers
1999-02-14  0:00           ` Bob Collins
1999-02-14  0:00             ` Pat Rogers
1999-02-16  0:00         ` Samuel Mize
1999-02-13  0:00     ` Matthew Heaney
1999-02-15  0:00     ` Jean-Pierre Rosen
1999-02-15  0:00       ` Ed Falis
1999-02-16  0:00         ` Jean-Pierre Rosen
1999-02-15  0:00 ` Jean-Pierre Rosen

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