comp.lang.ada
 help / color / mirror / Atom feed
* Re: Procedure types and dynamic binding
@ 1989-01-06 23:04 Erland Sommarskog
  1989-01-07 22:20 ` William Thomas Wolfe,2847,
  0 siblings, 1 reply; 28+ messages in thread
From: Erland Sommarskog @ 1989-01-06 23:04 UTC (permalink / raw)


Bill Wolfe writes: 
>    I'd think classes would be defined a bit differently!  A package
>    could contain declarations of variables, and we certainly don't want
>    variables included in a class definition (where class is defined as

This is half-true. Thus, we don't want them to be modifyable, but we 
want them to be readable. As far as I am concerned, writeable variable
in packages should be prohibited today, but, alas, wouldn't be a change
to rhyme with backwards compability. It should be avoided anyway.

>> But for inheritance we want all attributes, also those who do not 
>> appear in the specification part (or?), and particulary we probably 
>> want to have access to private types internal structure. 
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>    One of the most fundamental aspects of the ADT paradigm is that
>    an object is known to the outside world only as a type definition
>    and a set of predefined operations.  This provides the independence
>    which allows us to compile specifications and implementations separately.
>    Access to the internal structure of a private type violates the entire
>    concept of a "private" type.  

But can you as ADT designer always find out exactly what I want? Say 
you hand me a linked-list package. I discover that I need to reverse
a list, but does not have such an operation. With Ada today I have
three possibilies:
   1) Write Reverse_list using the existing primitives and place it 
      in my own package.
   2) Write my own extended list package, which calls yours and adds my own 
      Reverse_list.
   3) Re-hack your package, which gives me the possiblility to write a more
      efficient version.
1) has the disadvantge that my code contains something that does not belong
there. 2) Causes redundancy and duplicated declarations. 3) is maybe not 
available for various reasons. It resides in a library I cannot write to, 
and you are holiday. Besides other users would have a lot of recompilation 
triggered just before deliverance and get mad.
  
With inheritance there is a fourth possibility. I can write my extended  
list package to solely inherit all from yours and then add Reverse_list.
Depending if I want to be saved from changes, or need efficiency I
use your primitives, or the implementation.

For more info on this, the "open-closed principle", I once again refer
to Bertrand Meyer's "Object-Oriented Software Construction" where he
discusses these ideas.

>    Seriously though, there *is* a comp.lang.eiffel.  Perhaps you 
>    would feel more at home there rather than in comp.lang.ada.

I feel at home both here and there. Wouldn't say I found that comment
very serious, :-)

>>    Generic
>>...
>>    Package Binary_trees is
>>       ...
>>       Generic
>>          With Procedure Treat(Node : in     Node_type;  
>>                               Data : in out Data_type); 
>>       Procedure Traverse_forward(Tree : Tree_type);
>> 
>> (By the way, an example like the one above should be added to the validation
>> suite if it's not already there. A PC compiler I played with choked on the 
>> code above, and I believe it is/was validated.)
>
>     Why does Node need to be a parameter of Treat?  All you need is
>     something that will treat Data once Traverse_Forward has extracted
>     it from the Node.  Once you've removed the unnecessary parameter,
>     your package should compile perfectly.

You shouldn't work as a compiler. Whether Node is anything useful or
not could be discussed, but it's certainly perfectly legal Ada. If
it is not, tell me why and I write an error report about our Unix
compiler that accepts this. (The use for Node is that the user
may want a quick reference to some data, which he saves somewhere
else.)
-- 
Erland Sommarskog
ENEA Data, Stockholm              This signature is not to be quoted.
sommar@enea.se

^ permalink raw reply	[flat|nested] 28+ messages in thread
* Procedure types and dynamic binding
@ 1988-12-30 21:42 Erland Sommarskog
  1988-12-31 17:46 ` Bob Hathaway
  1989-01-05  7:38 ` William Thomas Wolfe,2847,
  0 siblings, 2 replies; 28+ messages in thread
From: Erland Sommarskog @ 1988-12-30 21:42 UTC (permalink / raw)


Bob Hathaway (rjh@cs.purdue.edu) writes:
>For yet another Ada 9X extension, I propose procedural variables.   
>...
>Procedural variables can
>avoid the redundant use of case statements by allowing an operation to be 
>stored within an Adt.     

I have stated my view before: a langauge revision should not introduce 
major changes, but stick to an overview of details that needs refining,
like character representation. There is one exception, though: if someone
comes up with a fully-fledged extention to give Ada dynamic binding to
make it a truly object-oriented langauge, I would whole-heartedily
support that proposal.

From this it is clear I think Bob Hathaway's idea should be rejected.
There are some gains with it, but not suffciently many. We will move
some tiny step against the O-O paradigm, but we will not be there.

Just for discussion: If we should make Ada an object-oriented langauge,
what should we add? Quite obvious seems package types to get classes.
If we could create several instances of a package, you have what Bob 
wanted and more. You have data *and* operations stored together. 
  But this doesn't suffice. This far we have just constructed task
types doesn't cost us a context change. We must have inheritance in
some way. How tell which other package types we inherit from? The 
WITH clause is not useful; it merely tells us which types we intend
to declare objects of. USE? Maybe. Doing USE on a package type to 
get all exported operations directly visible is of no interest. We 
should USE the package variable instead. But for inheritance we want 
all attributes, also those who do not appear in the specification 
part (or?), and particulary we probably want to have access to 
private types internal structure. So best would be a particular 
INHERIT clause.
  Multiple inheritance? That doesn't seem to be any problem. Ada
already has RENAMES which here could serve to remove clashes.
  Dynamic binding? We must be able to redefine a inherited operation.
There is no current construct for that in Ada so a REDEFINES clause
has to be added. (Rather useful is also deferred procedures that
inhereting packages *must* define, Ada more or less has this concept.) 
  We are about satisfied by now. Probably we need delaration a la
Eiffel, but if we could make all the rest, this would be no problem.
  Procedure types could be added for completeness, but doesn't feel
that necessary with all we added above.

Now, it is not as easy as this of course. Many detail rules has to
be thought out. And we would get an unnecessary big language. Would
we really need the sophisticated system with subtypes and derived
types? Well, we can't throw it away. 

Oh, one we need one more thing if go this way. Yes, you guessed it:
Garbage collection.

>It also allows individually parameterizable and 
>reprogrammable Adts since operations can be provided to alter the Adts actions
>or structure.  Generic subprogram parameters can only allow Adts to be set 
>once for any instantiation.  I use procedural variables and function pointers
>in Adts frequently when programming in languages other than Ada and am 
>convinced they are an elegant way to model Adt actions.

With the risk of saying something completely obvious: if you want variable
user-provided operations the following example with a tree-traversing
illustrates:

   Generic
      Type Data_type is limited private;
      With procedure Assign(A : in out Data_type; B : in Data_type);
      With function "<"(A, B : Data_type) return boolean is <>;
      With function ">"(A, B : Data_type) return boolean is <>;
   Package Binary_trees is
      Type Tree_type is private;        -- A tree with sorted data.
      Type Node_type is private;        -- A node in such a tree.
      ...
      Generic
         With Procedure Treat(Node : in     Node_type;  
                              Data : in out Data_type); 
      Procedure Traverse_forward(Tree : Tree_type);

(By the way, an example like the one above should be added to the validation
suite if it's not already there. A PC compiler I played with choked on the 
code above, and I believe it is/was validated.)
-- 
Erland Sommarskog
ENEA Data, Stockholm              This signature is not to be quoted.
sommar@enea.se

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

end of thread, other threads:[~1989-01-24  4:07 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-01-06 23:04 Procedure types and dynamic binding Erland Sommarskog
1989-01-07 22:20 ` William Thomas Wolfe,2847,
  -- strict thread matches above, loose matches on Subject: below --
1988-12-30 21:42 Erland Sommarskog
1988-12-31 17:46 ` Bob Hathaway
1989-01-05 10:02   ` William Thomas Wolfe,2847,
1989-01-07 18:05     ` Bob Hathaway
1989-01-07 21:21       ` William Thomas Wolfe,2847,
1989-01-08  1:49         ` Bob Hathaway
1989-01-08 19:01           ` William Thomas Wolfe,2847,
1989-01-08 23:10             ` Bob Hathaway
1989-01-09  1:47               ` William Thomas Wolfe,2847,
1989-01-09 20:19                 ` Bob Hathaway
1989-01-10  3:01                   ` William Thomas Wolfe,2847,
1989-01-10  3:06                   ` Bob Hathaway
1989-01-10 19:11                     ` William Thomas Wolfe,2847,
1989-01-11  2:08                       ` Bob Hathaway
1989-01-11 14:24                         ` William Thomas Wolfe,2847,
1989-01-11 17:51                           ` Barry Margolin
1989-01-11 22:54                             ` William Thomas Wolfe,2847,
1989-01-12 13:57                               ` Robert Firth
1989-01-12 19:09                                 ` William Thomas Wolfe,2847,
1989-01-14  0:46                                 ` Scott Moody
1989-01-15 18:28                                   ` William Thomas Wolfe,2847,
1989-01-24  4:07                                   ` Paul Stachour
1989-01-12  0:58                             ` William Thomas Wolfe,2847,
1989-01-12  6:12                               ` Barry Margolin
1989-01-11  2:10                       ` Bob Hathaway
1989-01-05  7:38 ` William Thomas Wolfe,2847,

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