comp.lang.ada
 help / color / mirror / Atom feed
* Visible or hidden derivation for controlled types ?
@ 1997-03-14  0:00 Mats Weber
  1997-03-15  0:00 ` Tom Moran
  1997-03-16  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 5+ messages in thread
From: Mats Weber @ 1997-03-14  0:00 UTC (permalink / raw)



There was a discussion some time ago in comp.lang.ada on whether Adjust,
Finalize and Initialize for Controlled types was better done in the
visible or private part of the package. In both cases, the type was
visibly derived from Ada.Finalization.Controlled.

I'd like to know if it is better to make types visibly derived from
Ada.Finalization.Controlled, or do that derivation in the private part:

Visible:

   generic
      type Element_Type is private;
      with function "=" (Left, Right : Element_Type) return Boolean;
      with function "<" (Left, Right : Element_Type) return Boolean;
   package Binary_Trees is

      type Binary_Tree is new Ada.Finalization.Controlled with private;

      procedure Adjust, ...

      ...

   private

      type Binary_Tree is new Ada.Finalization.Controlled with
         record
            ...
         end record;

   end;

or invisible:

   generic
      type Element_Type is private;
      with function "=" (Left, Right : Element_Type) return Boolean;
      with function "<" (Left, Right : Element_Type) return Boolean;
   package Binary_Trees is

      type Binary_Tree is private;

      ...

   private

      type Binary_Tree is new Ada.Finalization.Controlled with
         record
            ...
         end record;

      procedure Adjust, ...

   end;

Any ideas on which approach is best ?




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

* Re: Visible or hidden derivation for controlled types ?
  1997-03-14  0:00 Visible or hidden derivation for controlled types ? Mats Weber
@ 1997-03-15  0:00 ` Tom Moran
  1997-03-17  0:00   ` Jon S Anthony
  1997-03-16  0:00 ` Matthew Heaney
  1 sibling, 1 reply; 5+ messages in thread
From: Tom Moran @ 1997-03-15  0:00 UTC (permalink / raw)



I know of at least two Ada 95 compilers that don't take
   type T is private;
   procedure Initialize(X : in out T);
   ...
private
   type T is new Ada.Finalization.Controlled ...
to mean that the Initialize specified is the Controlled Initialzie for
T. If this is wrong, I'm sure it will eventually be corrected, but in 
the meantime it's certainly safer and more likely portable to admit in
the public part that T is a controlled type.  Why would you want that
fact to be private, BTW?




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

* Re: Visible or hidden derivation for controlled types ?
  1997-03-14  0:00 Visible or hidden derivation for controlled types ? Mats Weber
  1997-03-15  0:00 ` Tom Moran
@ 1997-03-16  0:00 ` Matthew Heaney
  1997-03-16  0:00   ` Robert Dewar
  1 sibling, 1 reply; 5+ messages in thread
From: Matthew Heaney @ 1997-03-16  0:00 UTC (permalink / raw)



In article <3329621A.3E9D@elca-matrix.ch>, Mats.Weber@elca-matrix.ch wrote:

>There was a discussion some time ago in comp.lang.ada on whether Adjust,
>Finalize and Initialize for Controlled types was better done in the
>visible or private part of the package. In both cases, the type was
>visibly derived from Ada.Finalization.Controlled.
>
>I'd like to know if it is better to make types visibly derived from
>Ada.Finalization.Controlled, or do that derivation in the private part:

I think the general advice according to the Rational is that the derivation
be done privately.  The guideline is that clients shouldn't care whether
the type inherits from Controlled; that is an implementation detail.  If
clients really don't care, then it's an even better idea to hide the
derivation, so the client can't accidently call Initialize or Adjust.

Of course, you might be building a primitive abstraction, where the clients
really do care that the abstraction is controlled.  For example, a data
structure library might contain an "unbounded collection," not for use by
general clients, but used only to implement other
higher-level-of-abstraction data structures.  (And the controlled-ness is
in turn hidden from the clients of those higher-level abstractions.)

If your binary tree is for general consumption, then hide the derivation
from Controlled.

Matt

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Visible or hidden derivation for controlled types ?
  1997-03-16  0:00 ` Matthew Heaney
@ 1997-03-16  0:00   ` Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1997-03-16  0:00 UTC (permalink / raw)



<<I think the general advice according to the Rational is that the derivation
be done privately.  The guideline is that clients shouldn't care whether
the type inherits from Controlled; that is an implementation detail.  If
clients really don't care, then it's an even better idea to hide the
derivation, so the client can't accidently call Initialize or Adjust.>>

I am not sure I agree, it is certainly part of the visible public
specification that the type has automatic storage collection on destruction,
which in Ada, typically means that it is controlled. 

It seems quite natural to put the Finalize in the public part, and use it
as the focal point for the documentation that provides for automatic
storage collection.

The counter argument is that the implementation might have garbage
collection, and not need the finalize, and that therefore it is indeed
an implementation detail.





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

* Re: Visible or hidden derivation for controlled types ?
  1997-03-15  0:00 ` Tom Moran
@ 1997-03-17  0:00   ` Jon S Anthony
  0 siblings, 0 replies; 5+ messages in thread
From: Jon S Anthony @ 1997-03-17  0:00 UTC (permalink / raw)



In article <332B1F05.31A7@bix.com> Tom Moran <tmoran@bix.com> writes:

> I know of at least two Ada 95 compilers that don't take
>    type T is private;
>    procedure Initialize(X : in out T);
>    ...
> private
>    type T is new Ada.Finalization.Controlled ...
> to mean that the Initialize specified is the Controlled Initialzie for
> T. If this is wrong,

Hmmm, I would have thought that this is correct as the fact that T is
such a derived type is private.

> the meantime it's certainly safer and more likely portable to admit in
> the public part that T is a controlled type.  Why would you want that
> fact to be private, BTW?

?????  I would also think that the "correct" thing to do is place the
Initialize in the private part.


/Jon

-- 
Jon Anthony
Organon Motives, Inc.
Belmont, MA 02178
617.484.3383
jsa@organon.com





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

end of thread, other threads:[~1997-03-17  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-14  0:00 Visible or hidden derivation for controlled types ? Mats Weber
1997-03-15  0:00 ` Tom Moran
1997-03-17  0:00   ` Jon S Anthony
1997-03-16  0:00 ` Matthew Heaney
1997-03-16  0:00   ` Robert Dewar

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