comp.lang.ada
 help / color / mirror / Atom feed
* maintenance of overriding subprograms
@ 1997-09-02  0:00 Stephen Leake
       [not found] ` <340DCE1D.6C5F@bix.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Stephen Leake @ 1997-09-02  0:00 UTC (permalink / raw)



The discussion of maintaining separate spec and implementation reminded
me of a potential maintenance problem with overriding subprograms of
derived types. Suppose we have:

   package Root is
      type Root_Type is tagged private;

      procedure Create (Item : in out Root_Type);
   private
      type Root_Type is tagged record
         Count : Integer;
      end record;
   end Root;

   package body Root is
      procedure Create (Item : in out Root_Type)
      is begin
         Item.Count := 0;
      end Create;
   end Root;

   package Derived is
      type Derived_Type is new Root.Root_Type with private;

      -- override Create (Root_Type)
      procedure Create (Item : in out Derived_Type);
   private
      type Derived_Type is new Root.Root_Type with record
         Leaves : Integer;
      end record;
   end Derived;

   package body Derived is
      procedure Create (Item : in out Derived_Type)
      is begin
         Root.Create (Root.Root_Type (Item));
         Item.Leaves := 0;
      end Create;
   end Derived;

Now suppose that in maintenance we add a parameter to Root.Create:

  procedure Create (Item : in out Root_Type; Max : in Integer := 0);

When we compile, the compiler tells us that the package body of Root
does not have a corresponding body for Create. However, it does not tell
us that Derived.Create no longer overrides Root.Create; Derived.Create
silently changes from an overriding subprogram to a "normal" subprogram.

To solve this, perhaps we could add a pragma:

pragma Confirm_Override ({subprogram_name});

which would generate a compile-time error if {subprogram_name} does not
override a root type subprogram. In Ada 200x, we could use the keyword
"new" for this:

new procedure Create (...);

which would have the same effect.

Any comments?
-- 
- Stephe




^ permalink raw reply	[flat|nested] 28+ messages in thread
* Re: maintenance of overriding subprograms
@ 1997-09-10  0:00 Marc Wachowitz
  0 siblings, 0 replies; 28+ messages in thread
From: Marc Wachowitz @ 1997-09-10  0:00 UTC (permalink / raw)




jsa@alexandria.organon.com (Jon S Anthony) wrote:
> > How on Earth am I supposed to know about the 17 primitive operations of
> > type T?
> 
> Right.  You can't without looking them all up.  And it gets a _lot_
> worse with MI.  This is just the old problem of OO (typically swept
> under the rug by OO fanatics) that it can cause all sorts of
> maintenance problems.

This particular problem could be solved by following a well-established
design principle of Ada (which was, IMO unfortunately, not done in this
case), namely to favour ease of reading and clarity over ease of writing:
Simply have each subtype define _all_ its methods explicitly, making any
calls of supertype-methods explicit (something similar could be done for
instance variables of the parent, too). Along with this, clearly separate
subtyping (type compatibility) and inheritance (implementation), where
the latter may only be used to adapt existing implementations as fields
(subobjects) for new types, which results in a programming style more like
delegation, though still allowing to redefine some (maybe a restricted subset)
methods of the adapted type. Generally there would be no relation between
the types of the new type and whichever types it may adapt for implementation,
though where appropriate, both may of course be declared to support the same
interfaces. This results both in more explicit (and thus hopefully clear)
relations between various types/implementations, and in better decoupling.
Single inheritance (i.e. adaption of subobjects) would be sufficient; however,
adaptions for various subobjects and methods for the resulting new type should
be able to freely call each other.

For some similar ideas, see Michael Franz' paper on the language Lagoona,
http://http://www.ics.uci.edu/~franz/PDF/Lagoona-ics-tr-96-40.pdf

> > Well, not really.  For example, think of all those clients of the
> > *parent* type that happily use the derived type without even *knowing*
> > about it.
> 
> And possibly shooting themselves in the foot and generating all sorts
> of maintenance nightmares to where the whole thing collapses under its
> own bloated opaque weight.

That's why subtyping should be constrained to be "safe for the innocent".
For an excellent (IMO) approach to this, see the paper of Barbara Liskov
and Jeannette M. Wing on "Family Values: A Behavioural Notion of Subtyping",
http://www.dstc.edu.au/AU/research_news/odp/typemgmt/related_work/
                                                       behav_subtype.html
(the last two lines are supposed to be one URL).

-- Marc Wachowitz <mw@ipx2.rz.uni-mannheim.de>




^ permalink raw reply	[flat|nested] 28+ messages in thread
* Re: maintenance of overriding subprograms
@ 1997-09-29  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  0 siblings, 0 replies; 28+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1997-09-29  0:00 UTC (permalink / raw)



 "John G. Volan" <johnv@AC3I.DSEG.TI.COM> writes:
>America, English has gained Amerindian words such as "okay", "squash",
>
    I thought the statement that "okay" was an American Indian word
    seemed to be incorrect - memory had me placing it as a U.S. slang
    term.

    A quick look at the OED (The New Shorter...) refreshed my memory.
    It originated from O.K. - representing the initials of Old
    Kinderhook, a nickname for President Martin Van Buren - hence also
    the hand gesture forming an "O-K" with the fingers.

    Back to the subject of Ada, Buckwheat?
    Oh-Tay 'Panky!

    MDC

Marin David Condic, Senior Computer Engineer     ATT:        561.796.8997
Pratt & Whitney GESP, M/S 731-96, P.O.B. 109600  Fax:        561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:   CONDICMA@PWFL.COM
===============================================================================
"I saw a bank that said "24 Hour Banking", but I don't have that much time."
        --  Steven Wright
===============================================================================




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

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

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-02  0:00 maintenance of overriding subprograms Stephen Leake
     [not found] ` <340DCE1D.6C5F@bix.com>
1997-09-04  0:00   ` John G. Volan
1997-09-07  0:00   ` Robert Dewar
1997-09-08  0:00     ` Robert A Duff
1997-09-09  0:00     ` Dan Johnston D.B.
1997-09-09  0:00       ` W. Wesley Groleau x4923
1997-09-09  0:00       ` Tom Moran
1997-09-10  0:00       ` Robert Dewar
1997-09-11  0:00         ` Dan Johnston D.B.
1997-09-12  0:00           ` Robert Dewar
1997-09-12  0:00           ` Richard A. O'Keefe
1997-09-12  0:00             ` Samuel Mize
1997-09-18  0:00             ` Shmuel (Seymour J.) Metz
1997-09-24  0:00               ` John G. Volan
1997-09-25  0:00                 ` Shmuel (Seymour J.) Metz
1997-09-26  0:00                   ` Richard A. O'Keefe
1997-09-05  0:00 ` Robert Dewar
1997-09-05  0:00   ` Stephen Leake
1997-09-05  0:00     ` Matthew Heaney
1997-09-07  0:00     ` Robert A Duff
1997-09-08  0:00       ` W. Wesley Groleau x4923
1997-09-09  0:00         ` Robert A Duff
1997-09-09  0:00           ` Jon S Anthony
1997-09-08  0:00       ` Tom Moran
1997-09-08  0:00         ` Stephen Leake
1997-09-10  0:00 ` Anonymous
  -- strict thread matches above, loose matches on Subject: below --
1997-09-10  0:00 Marc Wachowitz
1997-09-29  0:00 Marin David Condic, 561.796.8997, M/S 731-96

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