comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: "access constant" discriminant
Date: 24 Feb 2003 10:58:38 -0800
Date: 2003-02-24T18:58:38+00:00	[thread overview]
Message-ID: <1ec946d1.0302241058.88ca487@posting.google.com> (raw)
In-Reply-To: v5d2m6pi5q3tef@corp.supernews.com

"Randy Brukardt" <randy@rrsoftware.com> wrote in message news:<v5d2m6pi5q3tef@corp.supernews.com>...
> 
> Claw doesn't use access discriminants. That's in large part because they
> cause limited 'poisoning', as they're restricted to limited types. We
> prefered to use Adjust to make assignment work properly.

This may simply reflect a philosophical difference about whether types
should be limited or non-limited.  Certainly I have never agreed with
the CLAW decision to make window types non-limited, and to me a
non-limited window is completely wacky.

 
> Access discriminants are very powerful.  They are very much
> underutilized, probably because hardly anybody understands them.

I could make this argument about any language feature.

For example, when I was using Ada83, my experience was that many Ada
programmers never really understood what a private type was.  There
were many Ada83 programmers who didn't really grok the whole
object-oriented programming thing.

Another example: I worked on the F22 project for while, at Hughes.  No
one in the company seemed to know that you could return an
unconstrained array from a function:

   declare
      S : constant String := Name (File);
   begin

The problem was that Ada83 required the object to be marked as
"constant," so when the declaration

   declare
      S : String := Name (File);
   begin

didn't compile, everyone assumed that this meant you must return a
constrained array.  Of course this is incorrect -- but why didn't
anyone realize this?

I have observed a similar phenomenon among Ada95 programmers.  There
are many aspects of the Ada95 language with which many programmers are
unfamiliar.

For example, I gave a talk in London, and declared a private operation
that took the tagged type as an access parameter.  No one seemed to
realize that operations that accept the type as an access parameter
are primitive, and therefore dispatch when the parameter has type
T'Class.

Another of the speakers was talking about the problems he was having
with Unchecked_Access.  As it turns out, neither he nor anyone else in
his company knew that tagged types are passed by reference in Ada95. 
He was trying to prevent the "slicing" that can occur in C++ (and
which he thought would happen in Ada95 too), so he was declaring all
the type parameters using a named access type.  Of course, this is
incorrect, but why didn't anyone realize that tagged types are passed
by reference?


> Sweeping statements about programming style are not likely to be
> helpful. I tend to feel about finalization like Matt apparently does
> about access discriminants, but the only time I would say something like
> "No serious Ada program can be written without them." is when I'm
> looking for fight. Even though I believe that is true, I'm well aware
> that there are many, many Ada projects which have an irrational fear of
> finalization, and to characterize them as not being "serious" is not
> likely to make any friends.

Perhaps it was my use of the word "serious" that was confusing.  I
should have said "essential," with the same sense that Fred Brooks
used in his famous paper "Essence and Accidents in Software
Engineering."

http://atheism.about.com/library/glossary/general/bldef_essence.htm

C++ doesn't require you to use classes, but if you don't, it would be
a stretch to say that you're programming in "C++."  Really, you're
using a C++ compiler to compile a C program.  This is not necessarily
a bad thing -- after all, C++ gives you better compile-time error
checking and type-safe linkage.  But to not use classes you'd be
losing something "essential" to C++ programming.

The use of access discriminants in Ada95 is exactly analogous.  For
example, how would you add controlled-ness to a (tagged) type that is
part of type hierarchy that isn't already controlled?  The only way I
know is to do this:

   type NT is new T with private;
   ...
private
   type Control_Type (O : access NT) is
      new Limited_Controlled with null record;

   type NT is new T with record
      Control : Control_Type (NT'Access);
      ...
   end record;

This is an important Ada95 idiom with which every Ada95 needs to be
thoroughly familiar.  This idiom and others like it is why I
characterize access discriminants as "essential" (again, "per se" vs.
"per accidens") to programming in Ada95.



  parent reply	other threads:[~2003-02-24 18:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-10  8:26 "access constant" discriminant tmoran
2003-02-10 14:43 ` Frank J. Lhota
2003-02-10 18:57   ` tmoran
2003-02-15 19:17     ` Richard Riehle
2003-02-15 19:59       ` Larry Kilgallen
2003-02-15 23:53         ` Richard Riehle
2003-02-16  1:50           ` Eric G. Miller
2003-02-20  2:23         ` Matthew Heaney
2003-02-20 17:34         ` Stephen Leake
2003-02-21  0:42           ` Matthew Heaney
2003-02-21 10:41             ` Lutz Donnerhacke
2003-02-21 20:21               ` Randy Brukardt
2003-02-23 12:22                 ` Simon Wright
2003-02-24  7:06                 ` Dale Stanbrough
2003-02-24 18:58                 ` Matthew Heaney [this message]
2003-02-24 21:05                   ` Randy Brukardt
2003-02-25 14:15                     ` Frank J. Lhota
2003-02-26  1:05                       ` Randy Brukardt
2003-02-24 16:03               ` Matthew Heaney
2003-02-21 15:03             ` Hyman Rosen
2003-02-21 20:09               ` Randy Brukardt
2003-02-21 21:33               ` Matthew Heaney
2003-02-21 20:07             ` Randy Brukardt
2003-02-24 19:11               ` Matthew Heaney
2003-02-24 21:17                 ` Randy Brukardt
2003-02-25 17:49                   ` Richard Riehle
2003-02-20  2:23       ` Matthew Heaney
2003-02-20  2:20     ` Matthew Heaney
2003-02-10 19:26 ` Robert A Duff
2003-02-10 22:27 ` Rod Chapman
2003-02-11  2:00   ` Jeffrey Carter
2003-02-20  2:28   ` Matthew Heaney
2003-02-20  9:45     ` Lutz Donnerhacke
2003-02-20  2:17 ` Matthew Heaney
replies disabled

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