comp.lang.ada
 help / color / mirror / Atom feed
From: jvl@ocsystems.com (Joel VanLaven)
Subject: Re: Modest proposal, 3 of 3
Date: 1996/11/26
Date: 1996-11-26T00:00:00+00:00	[thread overview]
Message-ID: <1996Nov26.170524.19023@ocsystems.com> (raw)
In-Reply-To: 575aq0$t4j@netline-fddi.jpl.nasa.gov


Van Snyder (vsnyder@math.jpl.nasa.gov) wrote:
[Background snipped]
: PROPOSAL for next standardization of Ada

: Get rid of ".all".  When an access type appears, dereference it
: automatically.  This requires some way to copy "pointers."  PL/1 and
: Fortran 90 had the right idea:  Use a different syntax for "pointer
: assignment."  This is OK, because there are only two things you can
: do with pointers (in a sane language): dereference them and copy them.

: Both Fortran 90 and PL/1 use "a => b" to mean "change a so it points
: where b points" and "a = b" to mean copy the data where b points into
: the place where a points."  The latter in Ada requires "a.all := b.all".

: If one has a datum, say "A: T", and one later decides it's necessary to
: allocate it from the free store, the type of A changes from T to "access
: T".  That's not too bad.  But all the references change from "A" to
: "A.ALL".  That's bad.
[snip]

Indeed.  That is bad.  However, declaring "A" to be of type "access T" is
the problem, no the ".all" notation.  The Ada way to solve this problem
is to declare the object "A" to be aliased.  So, "A : T" becomes 
"A : aliased T"  and can be accessed used as both an accessable object and
in the way it was before.  If you want the object pointed to by "A" to
stay around after "A" is gone then you are opening up another can of worms.
In order to have a changeless transition from "T" to "access T" then the
memory will have to be deallocated automatically and in a safe manner.  So,
you seem to be advocating required, sophisticated garbage collection.
  Irrespective of whether your "problem" is indeed a problem at all,
you have given no reason why there is anything wrong with ".all" at all.
Your problem can be as easily solved by making dereferencing automatic and
keeping ".all"  The case you talk about is changing from "T" to "access T"
so there are no ".all" constructs involved at all.  Note that in most
cases this is already done.  Ada does have automatic dereferencing.  "A.foo"
is the same if "A" is of type "T" or type "access T" and access types are
most often used with records.
  The final point I want to make is a judgment call but is my opinion of
the way Ada should be, expecially given what I understand to be the design
goals of Ada.  Access types are dangerous.  Making something an access type
we make things more complex and start to run into problems of shared access
and memory allocation/deallocation etc.  It is generally not that hard for
a good programmer to deal with access types correctly, but it still remains
that many nasty errors are due to accessing the wrong memory or some such.
To blindly change an object to access to that object is asking for trouble.
If it must be done, better to have the compiler reject the program at the
points where there might be trouble than simply allow it to compile into
an incorrect program (like mixing access and non-access types).  It might
be that the language should be more restrictive in some way so that 
access type and "regular" types aren't assigned in the same way, but your
suggestion of making de-referencing automatic doesn't seem to be the way.

-- 
-- Joel VanLaven




      parent reply	other threads:[~1996-11-26  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-22  0:00 Modest proposal, 3 of 3 Van Snyder
1996-11-25  0:00 ` Robert A Duff
1996-11-25  0:00 ` Ken Garlington
1996-11-25  0:00   ` Mark A Biggar
1996-11-26  0:00     ` Robert Dewar
1996-11-26  0:00 ` Joel VanLaven [this message]
replies disabled

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