comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Derived private interface
Date: Tue, 26 Jul 2011 16:04:15 -0500
Date: 2011-07-26T16:04:15-05:00	[thread overview]
Message-ID: <j0na4g$ppi$1@munin.nbi.dk> (raw)
In-Reply-To: j0e0l1$5qh$1@tornado.tornevall.net

"Jeffrey Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:j0e0l1$5qh$1@tornado.tornevall.net...
> On 07/22/2011 03:59 PM, Randy Brukardt wrote:
>>
>> Given that the problem in question is related to dynamic dispatching and 
>> has
>> nothing in particular to do with extensions, this is an amazing 
>> statement.
>
> My statement was tongue in cheek, intended to express my dislike for 
> tagged types. Their only value seems to be all the traffic here from 
> people who run into problems trying to use them; this would be a much 
> quieter place without them.
>
> Maybe I'm missing something, but it seems to me that all dispatching in 
> Ada is related to extensions. If you have
>
> type T is tagged ...
>
> procedure P (V : in out T);
>
> and you never extend T, then you never get dispatching (in the sense that 
> a call to P results in something other than this P being called). To get 
> dispatching, you have to extend T
>
> type T2 is new T with ...
>
> overriding procedure P (V : in out T2);
>
> Then you can get a single call that sometimes calls P for T and other 
> times P for T2; that's dispatching. I don't know what dispatching means 
> without an extension and an overridden subprogram to dispatch to.

You're right in language terms, but as Dmitry points out, this occurs only 
because we're discussing tagged types (which include 3 of the 4 OOP legs in 
a single package). I was thinking more generally (and yes, I just complained 
about Dmitry doing that); what I was thinking of by "extension" was actually 
adding components to a type, not just deriving a a type with the same set of 
components.

As I was describing, most of the use of dispatching in Claw does not use any 
extension (that is, adding new components), it just changes the behavior of 
the dispatching routines appropriately. So there is only a change in 
behavior, not a change in representation.

Others have pointed out that using case statements as you suggested is 
essentially worthless unless you know every entity that the program is going 
to process before the fact. And real world programs are not like that (I 
have plenty of experience changing hundreds of case statements each time we 
make a change in node types or intermediate code definitions in Janus/Ada).

                                      Randy.



>> OTOH, programming by composition would provide nothing, in that there 
>> would
>> be no way to change the handlers for the base type. One could graft some
>> sort of unstructured mechanism on top of the objects (possibly using
>> access-to-subprograms), but this would provide many more opportunities 
>> for
>> mistakes (if you forget to set the access-to-subprogram value, the 
>> routine
>> might as well not exist).
>
> The equivalent of dispatching in programming by composition is a 
> subprogram that contains a case statement that contains calls to other 
> subprograms. No access-to-subprogram values involved. It does the exact 
> same thing as dispatching, except that it's easier to read and understand 
> and doesn't result in large numbers of "what am I doing wrong?" posts to 
> c.l.a.
>
>> Remember that there are four legs to the OOP stool: strong typing,
>> encapsulation, extension, and dynamic dispatching -- and each of these is
>> orthogonal to the others (shown by the fact that Ada has the first two
>> without even using tagged types, that is OOP). So there is no necessary
>> relationship between extension and dispatching (and working around the 
>> one
>> does nothing to solve a problem that mainly depends on the other).
>
> Again, I have no idea what dispatching even means in the absence of 
> extension.
>
> In Ada, "programming by extension" is achieved by the use of tagged types; 
> it includes dispatching. I have never seen anything implemented using 
> tagged types that could not also be implemented using programming by 
> composition. It follows that if there is a case where tagged types cause a 
> problem, the equivalent solution without tagged types is an effective work 
> around to the problem.
>
> Of course, in the case where there is no solution using tagged types, 
> there may also be no solution without using them.
>
> -- 
> Jeff Carter
> "If you think you got a nasty taunting this time,
> you ain't heard nothing yet!"
> Monty Python and the Holy Grail
> 23 





  parent reply	other threads:[~2011-07-26 21:04 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05  3:14 Derived private interface Rego, P.
2011-07-05  5:10 ` AdaMagica
2011-07-06  2:24   ` Rego, P.
2011-07-06  4:34   ` AdaMagica
2011-07-06  7:55     ` Georg Bauhaus
2011-07-06  8:30       ` AdaMagica
2011-07-06 12:59         ` Georg Bauhaus
2011-07-06 13:23           ` AdaMagica
2011-07-06 19:06             ` Randy Brukardt
2011-07-06 13:28           ` Simon Wright
2011-07-06 19:45           ` Randy Brukardt
2011-07-06 22:05             ` Georg Bauhaus
2011-07-06 23:56               ` Adam Beneschan
2011-07-07 14:09                 ` Georg Bauhaus
2011-07-07 15:10                   ` Adam Beneschan
2011-07-08  4:29                     ` AdaMagica
2011-07-08 19:08                       ` Randy Brukardt
2011-07-08 19:12                     ` Randy Brukardt
2011-07-07 15:19                   ` Georg Bauhaus
2011-07-07 10:37         ` Stephen Leake
2011-07-07 13:18           ` Georg Bauhaus
2011-07-08 19:23             ` Randy Brukardt
2011-07-08 21:41               ` Jeffrey Carter
2011-07-09  6:14                 ` Dmitry A. Kazakov
2011-07-22 22:59                 ` Randy Brukardt
2011-07-23  7:30                   ` Jeffrey Carter
2011-07-23  9:29                     ` Maciej Sobczak
2011-07-23 10:07                     ` Dmitry A. Kazakov
2011-07-26 21:04                     ` Randy Brukardt [this message]
2011-07-26 23:43                       ` Jeffrey Carter
2011-07-27 23:56                         ` Randy Brukardt
2011-07-28  0:18                           ` Jeffrey Carter
2011-07-28 10:06                         ` Maciej Sobczak
2011-07-28 23:24                           ` Randy Brukardt
2011-07-29  6:45                             ` Simon Wright
2011-07-30  0:04                               ` Randy Brukardt
2011-07-30  6:32                                 ` Simon Wright
2011-08-01  9:30                                   ` Alex R. Mosteo
2011-08-01 10:12                                     ` Dmitry A. Kazakov
2011-08-01 21:56                                       ` Randy Brukardt
2011-08-02 10:03                                         ` Dmitry A. Kazakov
2011-08-02 21:16                                           ` Randy Brukardt
2011-08-03  9:01                                             ` Dmitry A. Kazakov
2011-08-03 20:16                                               ` Randy Brukardt
2011-08-04  8:15                                                 ` Dmitry A. Kazakov
2011-08-09 21:10                             ` Maciej Sobczak
2011-08-09 21:35                               ` Randy Brukardt
2011-08-10  9:11                                 ` Dmitry A. Kazakov
2011-08-10 21:56                                   ` Randy Brukardt
2011-08-11  8:07                                     ` Dmitry A. Kazakov
2011-08-12  4:52                                       ` Randy Brukardt
2011-08-12  8:54                                         ` Dmitry A. Kazakov
2011-08-10 10:07                                 ` Maciej Sobczak
2011-08-10 11:26                                   ` Georg Bauhaus
2011-08-10 22:27                                     ` Randy Brukardt
2011-08-10 22:21                                   ` Randy Brukardt
2011-08-11 13:50                                     ` Maciej Sobczak
2011-08-12  4:43                                       ` Randy Brukardt
2011-08-12  7:00                                         ` Maciej Sobczak
2011-08-12 21:59                                           ` Randy Brukardt
2011-07-06 15:06       ` Adam Beneschan
2011-07-06 16:36       ` Dmitry A. Kazakov
2011-07-06 19:20       ` Randy Brukardt
replies disabled

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