comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Ada Interfaces and the Liskov Substitution Principle
Date: Mon, 04 Jun 2007 10:02:48 -0700
Date: 2007-06-04T10:02:48-07:00	[thread overview]
Message-ID: <1180976568.313756.322280@q66g2000hsg.googlegroups.com> (raw)
In-Reply-To: <14qx1ctt7r0kf$.on8dfqklv4jk$.dlg@40tude.net>

On 4 Cze, 10:08, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:

> > I was talking about access Object'Class with Circle and Triangle being
> > both derived from Object.
>
> What is the difference between the types access T'Class and T'Class?

Access T'Class can be reseated to point to some other object from
T'Class, even if that other object has different tag.
Thanks to this, access T'Class can be used to provide replacement
semantics for T'Class, where assignment wouldn't work.

I believe I get the Ada basics right.

> > We are going in circles. I say T'Class should be limited.
> > Even if T is not.
>
> If I'd say access T'Class should be limited even if T is not?

No, access Whatever should not be unconditionally limited, otherwise
there would be little justification for its existence in the type
system.
The raison d'etre for access T is the ability to *point* - and be
*reseated*.
Of course, there is a place for constant access Whatever, but this is
another story.

> > You can theoretize as long as you want and you can say (even rightly)
> > that replacement is doubly-dispatching, but there *is* a difference
> > between O(n+m) and O(n*m) - and this difference is what makes
> > assignment of T'Class simply unrealistic.
>
> No, that makes it unrealistic to manage this complexity using crude
> patterns instead of a consistent approach. The problem is here, the choice
> is between language support and manual cascaded case-statements.

No, there is no choice whatsoever. There is nothing that cascaded case-
statements can buy you that you couldn't do with dispatch (except
maybe static coverage tests - but these don't exist in open
hierarchies).
There are fundamental reasons for which assignment for T'Class doesn't
make sense (it would lead to objects that can change type at runtime -
you cannot get further away from Ada than that) and no matter what
magic you try, you will always hit the same wall.
Consider (again):

procedure Swap(X : in out Object'Class; X in out Object'Class)
begin
   -- whatever
end Swap;

and then:

declare
  X : Triangle;
  Y : Circle;
begin
  Swap(X, Y);
  -- oops
end;

It does not matter what is inside Swap. Double-dispatch, cascading
case, unchecked magic, whatever. These are all low-level details of
something that just doesn't fly anyway.

> > This, however, brings another point - if you want to execute different
> > assignment tasks depending on both LHS and RHS *types*, then let's
> > extend it a bit: I want to execute different tasks depending on
> > current *values* of both LHS and RHS. After all, if assignment is
> > supposed to be doubly-dispatching and if it's also supposed to be no
> > different than hypothetical Assign(X, Y), then I should be able to do
> > this, right?
>
> Wrong. These are independent. Double dispatch controls the choice of the
> specific body, it tells nothing about how this body has to be assembled.

Yes, but this shows that assignment in Ada cannot be modeled by any
hypothetical Assign subprogram. No analogies here. This in turn means
that introducing full double-dispatch to the discussion doesn't help
much, because implementing it would not be at all similar to anything.

> In some cases you might really want LHS being finalized
> before the overridden part of the assignment, like when it holds an
> expensive resource.

1. In *some* cases. In those cases I can take this decision on my own.

2. Actually, in those cases when LHS keeps expensive resource I would
very much welcome the ability to reuse it, if possible. Consider:

declare
   S1 : My_String_Type := "abcd";
   S2 : My_String_Type := "xyz";
begin
   S1 := S2;
end;

No need to finalize LHS here (and reallocate again to hold a copy of
RHS). Other examples abound.

Sorry to say this, but when I see things like *this*, I have an
impression that Ada is SbyC (Slow by Construction - you can quote
me :-) ). This is *obvious* optimization opportunity!

But that was aside, nothing about T'Class being limited.

> My approach, not shared here, is that the programmer should have more
> control over this, when he wants.

Hm... do we agree again? :-)

> The constructors, destructors,
> assignments and aggregates are all polymorphic subroutines composed
> differently from normal primitive and class-wide operations.

Agreed with exceptions:
- constructors cannot be polymorphic, since there is no tag yet (you
might dispatch on something different, though, but this is irrelevant)
- assignments are banned anyway ;-)

Destructors are obviously polymorphic.

> In a better
> language one should be able to describe all these decompositions uniformly,
> with a higher-level mechanism of polymorphic subprograms.

Not really. The problem is that these things work on the border of
object's life and death and for this reason they cannot be first-class
citizens in the world of polymorphic operations.

> > Unfortunately, this is completely broken in Ada.
>
> It is not broken, it does not exist. Adjust is not an assignment, it is
> hack to provide functionality without much rethinking.

Hacks make things broken.
Every language has its hacks, but this one is just too fundamental to
be easily forgiven. ;-)

--
Maciej Sobczak
http://www.msobczak.com/




  reply	other threads:[~2007-06-04 17:02 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-23 19:47 Ada Interfaces and the Liskov Substitution Principle Stefan Lucks
2007-05-23 20:32 ` Ludovic Brenta
2007-05-23 22:00   ` Randy Brukardt
2007-05-24  0:56     ` Anh Vo
2007-05-24 18:27     ` Pascal Obry
2007-05-24 18:39       ` Dmitry A. Kazakov
2007-05-24 18:51         ` Pascal Obry
2007-05-24 22:44         ` Randy Brukardt
2007-05-24  6:57   ` Stefan Lucks
2007-05-23 20:54 ` Maciej Sobczak
2007-05-23 21:58   ` Randy Brukardt
2007-05-24  7:29     ` Maciej Sobczak
2007-05-24  8:02       ` Dmitry A. Kazakov
2007-05-24 12:58         ` Maciej Sobczak
2007-05-24 13:42           ` Dmitry A. Kazakov
2007-05-24 22:08           ` Robert A Duff
2007-07-01  1:00             ` David Thompson
2007-05-24 22:58           ` Randy Brukardt
2007-05-25  7:52             ` Maciej Sobczak
2007-05-25  8:21               ` Dmitry A. Kazakov
2007-05-25 20:27                 ` Maciej Sobczak
2007-05-26  7:48                   ` Dmitry A. Kazakov
2007-05-27  8:30                     ` Maciej Sobczak
2007-05-27 10:04                       ` Dmitry A. Kazakov
2007-05-29  8:03                         ` Maciej Sobczak
2007-05-29 13:18                           ` Dmitry A. Kazakov
2007-05-29 13:32                             ` Dmitry A. Kazakov
2007-05-29 15:34                             ` Maciej Sobczak
2007-05-29 17:07                               ` Dmitry A. Kazakov
2007-05-30  7:40                                 ` Maciej Sobczak
2007-05-30  8:43                                   ` Dmitry A. Kazakov
2007-05-30 12:54                                     ` Maciej Sobczak
2007-05-30 13:56                                       ` Dmitry A. Kazakov
2007-05-30 16:49                                         ` vgodunko
2007-05-30 20:52                                         ` Maciej Sobczak
2007-05-31  8:15                                           ` Dmitry A. Kazakov
2007-05-31 13:46                                             ` Maciej Sobczak
2007-06-01  7:29                                               ` Dmitry A. Kazakov
2007-06-01 13:32                                                 ` Maciej Sobczak
2007-06-01 14:53                                                   ` Dmitry A. Kazakov
2007-06-01 20:31                                                     ` Maciej Sobczak
2007-06-02  8:19                                                       ` Dmitry A. Kazakov
2007-06-02 16:49                                                         ` Maciej Sobczak
2007-06-03  7:09                                                           ` Dmitry A. Kazakov
2007-06-03 22:04                                                             ` Maciej Sobczak
2007-06-04  8:08                                                               ` Dmitry A. Kazakov
2007-06-04 17:02                                                                 ` Maciej Sobczak [this message]
2007-06-05  8:35                                                                   ` Dmitry A. Kazakov
2007-06-05 22:12                                                                     ` Maciej Sobczak
2007-06-06  8:21                                                                       ` Dmitry A. Kazakov
2007-06-06 14:46                                                                         ` Maciej Sobczak
2007-06-06 15:11                                                                           ` Maciej Sobczak
2007-06-06 15:32                                                                       ` Markus E Leypold
2007-05-24 10:42       ` Georg Bauhaus
2007-05-24 13:41         ` Dmitry A. Kazakov
2007-05-25 16:59         ` Markus E Leypold
2007-05-28  9:52           ` Georg Bauhaus
2007-05-28 11:50             ` Dmitry A. Kazakov
2007-05-28 23:32               ` Georg Bauhaus
2007-05-29 12:05                 ` Dmitry A. Kazakov
2007-05-29 13:33                 ` Georg Bauhaus
2007-05-29 17:29                   ` Dmitry A. Kazakov
2007-05-29 20:46                     ` Georg Bauhaus
2007-05-30  7:53                       ` Dmitry A. Kazakov
2007-05-30 13:18                       ` Georg Bauhaus
2007-05-31 10:27                         ` Dmitry A. Kazakov
2007-05-31 11:44                         ` Georg Bauhaus
2007-06-01  7:37                           ` Dmitry A. Kazakov
2007-06-01 10:07                             ` Markus E Leypold
2007-06-01 11:41                             ` Georg Bauhaus
2007-06-01 13:07                               ` Dmitry A. Kazakov
2007-05-28 13:47             ` Markus E Leypold
2007-05-28 23:12               ` Georg Bauhaus
2007-05-28 13:56             ` Markus E Leypold
2007-05-28 23:00               ` Georg Bauhaus
2007-05-24  7:39 ` Dmitry A. Kazakov
2007-05-24 11:12   ` Stefan Lucks
2007-05-24 13:56     ` Dmitry A. Kazakov
2007-05-24 14:41       ` Stefan Lucks
2007-05-24 15:46         ` Dmitry A. Kazakov
2007-05-24 15:00       ` Georg Bauhaus
replies disabled

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