comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada Interfaces and the Liskov Substitution Principle
Date: Tue, 29 May 2007 15:18:58 +0200
Date: 2007-05-29T15:16:43+02:00	[thread overview]
Message-ID: <kzd3t06bdinz$.1jcbmu9dqomx7$.dlg@40tude.net> (raw)
In-Reply-To: 1180425803.422075.100090@o5g2000hsb.googlegroups.com

On 29 May 2007 01:03:23 -0700, Maciej Sobczak wrote:

> On 27 Maj, 12:04, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
>> To ban something in the language you have to translate the ban into
>> language terms. That could be either by syntax or by semantic rules.
>> Because syntactically banned assignments are indistinguishable from legal
>> ones, the only mechanics you could use for this is matching types. The
>> types in question are from the same hierarchy (covariant). This lets mixing
>> such types. So it *must* be contravariant to be banned = the operation
>> (":=") will not be inherited in the argument of interest upon inheritance.
> 
> OK, now I see your point. I have nothing against following this path -
> assignment statement *is* special anyway. What could go wrong if we
> say that assignment is not inherited?

Then you will have a messy bunch of overloaded ones. There are two variants
of:

1. Use of T'Class, I considered this in a previous post, it is ambiguous.

2. Non-primitive operation (ugly hack). This will not work on class-wide
arguments:

   X : T'Class := Y; -- Illegal, ":=" isn't defined on LHS T'Class

>> And I don't see why it is a mess. What is wrong in assignment of
>> UTF8_String to Wide_String, both from String'Class?
> 
> Probably design issue. Character encoding can/should be a strategy
> inside a String, you don't need to subclass the whole thing just for
> it. There are many aspects on which you could parameterize String and
> with some of them being orthogonal you could quickly end up with
> milion leaf classes.

So? This is exactly the reason why I want to keep them all in one class.
Encoding is a constraint put on the object. It is mapped to a type to be
able to implement string operations independently, for each encoding
through dispatching rather than by ugly nested case-statements.

And what about fixed vs. bounded vs. unbounded axis? Why a fixed string
shouldn't be assigned to an unbounded one and reverse? How are you going to
design such stuff without polymorphism? By cut'n'paste, as RM does? At some
point they too had got tired:

"... For each of the packages Strings.Fixed, Strings.Bounded,
Strings.Unbounded, and Strings.Maps.Constants the corresponding wide string
package has the same contents except that 

� Wide_Space replaces Space 

� Wide_Character replaces Character 

� Wide_String replaces String ..." (:-))

>> The very definition of a class says that types there share class-wide and
>> primitive operations. If that is not the case: ":=" is not shared, then
>> either it is not a class (= don't derive! if need not) or there is no ":="
>> (= make it limited! if unsure). Looks much like a design problem.
> 
> Yes. That's why I say that I have never seen any reasonable hierarchy
> that supports assignments.

Strings above.

>> There is nothing special in
>> assignments.
> 
> Yes, there is - they are generated. This is deceptive, because it
> makes one think that it should all work by magic.

It means that the language is unable to express assignments in its own
terms. I don't want such language. In fact, the rules you propose for
assignments can be expressed in Ada terms:

type X is private;
type Y is new Y;  -- Done

Don't use classes if you don't want to assign them.

> Another reason why they are special is that they are intuitively
> associated with some particular effects and these effects cannot be
> reasonably provided in an automated way. That's why I think that
> assignments of class-wide types should be forbidden.

No, it is much simpler to provide multi-methods and make it consistent. The
only problem Ada has with assignment is that it is a fake MD. If it were a
true MD, then upon inheritance (per extension) from a tagged private T, the
compiler would complain: "hey, I don't know how to assign T to S!" This
would force you to override S := T in a reasonable way (existing for
String) or else to rethink your allegedly wrong design. Presently Ada
silently generates raise Constraint_Error, which is not good.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2007-05-29 13:18 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 [this message]
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
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