comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Is this expected behavior or not
Date: Thu, 28 Mar 2013 14:50:48 +0100
Date: 2013-03-28T14:50:48+01:00	[thread overview]
Message-ID: <cqf0yy6q930$.1sdzw45bc0c1w.dlg@40tude.net> (raw)
In-Reply-To: kivi42$hmu$1@munin.nbi.dk

On Wed, 27 Mar 2013 14:42:47 -0500, Randy Brukardt wrote:

> The problem is that a slice ought to be a referential object as you put it, 
> and a "regular" object is definitely *not* a referential object (a copy 
> copies the data).

What is "regular" object here? String?

> I don't see any way for a single data type to have two 
> different behaviors

These are two data types, string and slice. Are you treating slice as an
Ada-subtype of string? I consider slice a member of same class as string,
yet a distinct type (in Ada sense). This is like 4.1.5, but in the same
type hierarchy.

>>> You missed the point altogether. You can't dispatch in general on untagged
>>> types because overriding operations may have different modes and subtypes
>>> for the parameters. So what *is* the profile of the operation for T'Class,
>>> and how can it work?
>>>
>>> Consider:
>>>
>>>      Type Int is range 1 .. 10;
>>>      procedure Op (A, B : in Int);
>>>
>>>      Type Der is new Int;
>>
>> This is not derivation within the class, it is a "type-cloning." Type
>> cloning creates a new class and new a type (all types up the hierarchy). 
>> We need some syntax to indicate the difference.
>>
>>   type Der is new Int <whatever>;
>>
>> It is unfortunate that tagged types reused "is new" for a purpose
>> completely different from type cloning.
> 
> Nobody wants "type cloning".

It is a very useful building block to me. Anyway it is Ada 83 legacy.

> I have no idea why anyone that wants 'Class 
> would want to avoid maximizing the interoperability of types.

Sometimes we want types related, sometimes we don't, while reusing existing
implementations. The language should support programmer's choice.

> The original motivating example for Integer'Class was:
> 
>      Put (Obj : Integer'Class; Width : Count := 0);
> 
> so that one didn't need to understand generic instantiations just to do 
> simple I/O of strongly typed entities.

Yes.

Cloned Integer will "inherit" this Put operation in Ada 83 sense. Ada 83
cloning is orthogonal to type hierarchies. You get a new hierarchy when you
clone a type.

> I don't think a version of untagged'Class that did not work on existing 
> derived types would fly.

Astonishing that you even considered that possibility. In my view they are
completely independent things.

> In any case, I didn't realize that you were making an entire new kind of 
> type derivation

To me it is exactly same as tagged extension when you add nothing to the
existing representation.

We also need "extension" that drops parent's representation altogether.
E.g. something like:

   type Character is new Unsigned_8 -- or enumeration, whatever
      and Wide_Wide_Character'Interface;

Character is member of Wide_Wide_Character'Class with a representation
different from Wide_Wide_Character.

>> Moreover, it is highly desired to that cloning were available for tagged
>> types as well:
>>
>>   package Original is new Ada.Containers.Vectors ...;
>>   type Clone is new Original.Vector; -- Cloning, not extending!
>>
>> Now, I have to hierarchies of Vector, not very useful in this particular
>> case, because of missing helper types, but anyway.
> 
> Pointless complication. I thought you were trying to simplify the language!

Making it regular is a simplification.

>>>      overriding
>>>      procedure Op (A : in out Der; B : in Der);
>>
>> This is not an overriding since the mode is different.
> 
> It *is* an overriding in Ada 83, and it still is in Ada 2012. I agree that 
> it should not have been, but that is irrelevant because we're stuck with it.

Only when Der is derived using Ada 83 construct. Int'Class will be built
using "extension."

>>>      Obj : Int'Class := Der'(1);
>>>      Op (A => 1, B => Obj); -- Legal??
>>
>> MD is not fully implemented in Ada, but anyway, presuming that Op is a
>> multi-method, that the mode is "in" and that 1 is Universal_Integer (is
>> it?), the above is illegal because Op is not a method of
>> Universal_Integer'Class. You would have to write it as:
>>
>>   Op (A => Der'(1), B => Obj);  -- Same tags
>>   Op (A => Int'(1), B => Obj);  -- Different tags, Constraint_Error
> 
> This seems wrong; an integer literal usually gets its type from context. 
> It's only a value of type Universal_Integer if there is no type given from 
> context (as in a type conversion or number declaration). I was presuming 
> that integer literals act as tag-indeterminate functions (the most sensible 
> model; if you have constants for a tagged type you usually would model them 
> as tag-indeterminate functions - for instance, the constants Zero and One in 
> a universal arithmetic package), you don't need multiple dispatch: the Ada 
> dispatching rules simply calls the correct version of the function for the 
> tag of the object. And that's what we would want to happen for integer 
> literals (that's the closest analogy to what happens for existing 
> expressions).

This is one of possible interpretations of Ada semantics. You consider
literals primitive operations, e.g.

   function "1" return Int;

In Ada 95 such function has to be overridden, when Der extends Int.
However, if the representation is inherited and not changed, the rule could
be that the compiler silently overrides all literals:

   overriding function "1" return Der;

In this case you will have 1 overloaded. Op will become ambiguous. The
alternative with different types can be discarded using some preference
rules, e.g. domination, and thus ambiguity resolved.

>>> An interface can't have "..." as the parameter type for Write; there has 
>>> to be something there.
>>
>>   procedure Write (File : in out File_Access; Data : Stream_Element_Array)
>>      is abstract;
>>
>>> And that's the target type! Say again how it is that you
>>> are not exposing this type??
>>
>> The target is File. I would gladly have MD and a hierarchy for the second
>> parameter, but that is another story for now.
> 
> OK, if the target is File, then you know that - that's public information. 
> When you dereference a File_Handle, you get a File. You don't have to make 
> the contents of File public, just it's name. So I still don't see why you 
> think this is a problem.

I don't want to expose File at all. Public views should have no access to
it, otherwise than indirectly through the handle. E.g. they should not be
able to get an access the file object, store it somewhere, deallocate it,
use stream attributes on it, and perform any other fancy stuff.
Furthermore, later on, a decision may fall to replace file descriptor with
something completely different keeping code that uses handles intact. It is
good old information hiding principle.

>> Because whether a message is relevant to the choice if the program were OK
>> to deploy depends now on the message content. The language does not help 
>> me anymore to indicate it as a bug.
> 
> But there is absolutely nothing new about this.

There is nothing new that people die, yet nobody actually likes it.

> GNAT has a variety of 
> warnings (calling everything it displays a "warning" in order to avoid 
> arguments about its particular classifications of message), but most people 
> choose to treat some subset of them as errors that have to be removed before 
> deployment. You would do that same; choose a *class* of warnings that have 
> to be removed; there is no parsing of messages needed. If a warning in the 
> prohibited class exists, the program is not ready for deployment.

Some C compilers give warning when you write:

   if (x = 1) ...

> Yes, this means you need to develop a coding standard and a development 
> standard to ensure that these these things are followed. But not having 
> those in some form is just lousy programming management.

Error checks do not belong to coding standards. Coding standard, and
testing, and code review etc are there when compiler checks were
impossible.

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

  reply	other threads:[~2013-03-28 13:50 UTC|newest]

Thread overview: 242+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-11 19:42 Is this expected behavior or not Anh Vo
2013-03-11 20:01 ` Robert A Duff
2013-03-11 20:41   ` Shark8
2013-03-12  9:27     ` Dmitry A. Kazakov
2013-03-12 17:19       ` Robert A Duff
2013-03-12 17:42         ` Dmitry A. Kazakov
2013-03-12 18:04           ` Georg Bauhaus
2013-03-12 18:21             ` Dmitry A. Kazakov
2013-03-12 22:23               ` Georg Bauhaus
2013-03-13  8:49                 ` Dmitry A. Kazakov
2013-03-13  9:45                   ` J-P. Rosen
2013-03-13 13:31                     ` Dmitry A. Kazakov
2013-03-13 14:34                       ` Georg Bauhaus
2013-03-13 15:51                         ` Dmitry A. Kazakov
2013-03-13 16:56                           ` Jeffrey Carter
2013-03-13 17:09                             ` Shark8
2013-03-13 17:32                           ` Georg Bauhaus
2013-03-13 19:28                             ` Dmitry A. Kazakov
2013-03-13 21:01                               ` Randy Brukardt
2013-03-13 21:18                                 ` Dmitry A. Kazakov
2013-03-14 21:51                                   ` Randy Brukardt
2013-03-15  1:10                                     ` Adam Beneschan
2013-03-15 21:22                                       ` Randy Brukardt
2013-03-15  9:20                                     ` Dmitry A. Kazakov
2013-03-15 21:43                                       ` Randy Brukardt
2013-03-16  7:56                                         ` Dmitry A. Kazakov
2013-03-18 22:52                                           ` Randy Brukardt
2013-03-19 10:32                                             ` Dmitry A. Kazakov
2013-03-13 21:37                               ` Georg Bauhaus
2013-03-14 11:18                                 ` Dmitry A. Kazakov
2013-03-14 12:37                                   ` Georg Bauhaus
2013-03-14 14:26                                     ` Dmitry A. Kazakov
2013-03-14 14:57                                       ` Georg Bauhaus
2013-03-14 15:51                                         ` Anh Vo
2013-03-14 16:21                                       ` J-P. Rosen
2013-03-14 17:29                                         ` Dmitry A. Kazakov
2013-03-14 18:16                                           ` Georg Bauhaus
2013-03-15  9:33                                             ` Dmitry A. Kazakov
2013-03-15 10:05                                               ` Georg Bauhaus
2013-03-15 11:15                                                 ` Dmitry A. Kazakov
2013-03-14 22:12                                           ` Randy Brukardt
2013-03-15  9:46                                             ` Dmitry A. Kazakov
     [not found]                                             ` <ewe0v3ck1xdo$.e8rtuof27ke6$.dlg@40tude.net >
2013-03-15 21:17                                               ` Randy Brukardt
2013-03-16  7:51                                                 ` Dmitry A. Kazakov
2013-03-16  9:30                                                   ` Georg Bauhaus
2013-03-16 10:27                                                     ` Dmitry A. Kazakov
2013-03-16 11:37                                                       ` Georg Bauhaus
2013-03-16 13:04                                                         ` Dmitry A. Kazakov
2013-03-16 16:10                                                           ` Georg Bauhaus
2013-03-16 17:47                                                             ` Dmitry A. Kazakov
2013-03-18 22:36                                                   ` Randy Brukardt
2013-03-19 10:14                                                     ` Dmitry A. Kazakov
2013-03-19 14:23                                                       ` Georg Bauhaus
2013-03-19 15:13                                                         ` Dmitry A. Kazakov
2013-03-19 16:52                                                           ` Georg Bauhaus
2013-03-19 17:31                                                             ` Dmitry A. Kazakov
2013-03-19 20:07                                                               ` J-P. Rosen
2013-03-19 20:45                                                                 ` Dmitry A. Kazakov
2013-03-19 21:59                                                                   ` J-P. Rosen
2013-03-20 10:04                                                                     ` Dmitry A. Kazakov
2013-03-20 11:01                                                                       ` J-P. Rosen
2013-03-20 13:21                                                                         ` Dmitry A. Kazakov
2013-03-20 23:31                                                                           ` Randy Brukardt
2013-03-21  9:08                                                                             ` Dmitry A. Kazakov
2013-03-22 10:23                                                                           ` J-P. Rosen
2013-03-22 14:54                                                                             ` Dmitry A. Kazakov
2013-03-22 22:18                                                                               ` J-P. Rosen
2013-03-22 23:05                                                                                 ` Shark8
2013-03-23  8:32                                                                                   ` Dmitry A. Kazakov
2013-03-23  8:14                                                                                 ` Dmitry A. Kazakov
2013-03-23  9:02                                                                                   ` J-P. Rosen
2013-03-23 10:19                                                                                     ` Dmitry A. Kazakov
2013-03-23 21:53                                                                                       ` J-P. Rosen
2013-03-24  8:17                                                                                         ` Dmitry A. Kazakov
2013-03-24  8:27                                                                                           ` J-P. Rosen
2013-03-24 13:01                                                                                             ` AdaMagica
2013-03-25  8:32                                                                                             ` Dmitry A. Kazakov
2013-03-25  9:19                                                                                               ` Georg Bauhaus
2013-03-25 10:08                                                                                                 ` Dmitry A. Kazakov
2013-03-19 21:37                                                       ` Randy Brukardt
2013-03-20  8:48                                                         ` Dmitry A. Kazakov
2013-03-14 16:22                                       ` Shark8
2013-03-14 17:08                                         ` Dmitry A. Kazakov
2013-03-13 22:34                               ` Robert A Duff
2013-03-14  9:09                                 ` Dmitry A. Kazakov
2013-03-14  9:27                                   ` Georg Bauhaus
2013-03-13 17:05                         ` Shark8
2013-03-13 17:45                           ` Simon Wright
2013-03-13 19:37                             ` Dmitry A. Kazakov
2013-03-13 19:54                               ` Simon Wright
2013-03-13 20:54                                 ` Dmitry A. Kazakov
2013-03-13 21:28                                   ` Simon Wright
2013-03-14  9:16                                     ` Dmitry A. Kazakov
2013-03-14 16:42                                       ` Simon Wright
2013-03-14 17:05                                         ` Dmitry A. Kazakov
2013-03-13 22:12                                   ` Robert A Duff
2013-03-13 21:47                                 ` Jeffrey Carter
2013-03-13 21:09                               ` Randy Brukardt
2013-03-13 22:48                                 ` Shark8
2013-03-14 22:01                                   ` Randy Brukardt
2013-03-15  3:27                                     ` Shark8
2013-03-15 21:05                                       ` Randy Brukardt
2013-03-15 21:46                                         ` Robert A Duff
2013-03-16  5:52                                           ` Shark8
2013-03-16  7:41                                             ` Dmitry A. Kazakov
2013-03-16 16:55                                               ` Shark8
2013-03-16 17:36                                                 ` Dmitry A. Kazakov
2013-03-16 21:51                                                   ` Shark8
2013-03-17  9:36                                                     ` Dmitry A. Kazakov
2013-03-18 23:13                                                       ` Randy Brukardt
2013-03-19  9:12                                                         ` Dmitry A. Kazakov
2013-03-19 21:19                                                           ` Randy Brukardt
2013-03-20 11:21                                                             ` Dmitry A. Kazakov
2013-03-20 23:57                                                               ` Randy Brukardt
2013-03-21 10:30                                                                 ` Dmitry A. Kazakov
2013-03-21 23:27                                                                   ` Randy Brukardt
2013-03-22 16:07                                                                     ` Dmitry A. Kazakov
2013-03-22 20:10                                                                       ` Shark8
2013-03-22 20:51                                                                         ` Dmitry A. Kazakov
2013-03-22 23:34                                                                           ` Robert A Duff
2013-03-23  8:41                                                                             ` Dmitry A. Kazakov
2013-03-23  2:29                                                                           ` Nasser M. Abbasi
2013-03-23  2:33                                                                       ` Randy Brukardt
2013-03-23  4:44                                                                         ` Shark8
2013-03-25 22:24                                                                           ` Randy Brukardt
2013-03-26  1:15                                                                             ` Shark8
2013-03-23  9:53                                                                         ` Dmitry A. Kazakov
2013-03-25 22:58                                                                           ` Randy Brukardt
2013-03-26 10:52                                                                             ` Dmitry A. Kazakov
2013-03-26 21:31                                                                               ` Randy Brukardt
2013-03-27  9:37                                                                                 ` Dmitry A. Kazakov
2013-03-27 19:42                                                                                   ` Randy Brukardt
2013-03-28 13:50                                                                                     ` Dmitry A. Kazakov [this message]
2013-03-28 21:55                                                                                       ` Randy Brukardt
2013-03-29 12:26                                                                                         ` Dmitry A. Kazakov
2013-03-30  0:49                                                                                           ` Randy Brukardt
2013-03-30  2:55                                                                                             ` Shark8
2013-04-01 23:43                                                                                               ` Messaging question [was: Is this expected behavior or not] Randy Brukardt
2013-03-30  9:20                                                                                             ` Is this expected behavior or not Dmitry A. Kazakov
2013-04-02  0:40                                                                                               ` Randy Brukardt
2013-04-02  8:44                                                                                                 ` Dmitry A. Kazakov
2013-04-02 21:54                                                                                                   ` Randy Brukardt
2013-04-03  8:54                                                                                                     ` Dmitry A. Kazakov
2013-04-04  0:04                                                                                                       ` Randy Brukardt
2013-04-04  8:26                                                                                                         ` Dmitry A. Kazakov
2013-04-04 20:31                                                                                                           ` Randy Brukardt
2013-04-05  9:57                                                                                                             ` Dmitry A. Kazakov
2013-04-05 12:45                                                                                                               ` Stefan.Lucks
2013-04-05 12:49                                                                                                                 ` Stefan.Lucks
2013-04-05 14:19                                                                                                                   ` Dmitry A. Kazakov
2013-04-05 14:44                                                                                                                     ` Stefan.Lucks
2013-04-05 16:11                                                                                                                       ` Dmitry A. Kazakov
2013-04-05 19:02                                                                                                                         ` Stefan.Lucks
2013-04-05 19:34                                                                                                                           ` Dmitry A. Kazakov
2013-04-05 20:23                                                                                                                             ` Stefan.Lucks
2013-04-06  7:39                                                                                                                               ` Dmitry A. Kazakov
2013-04-07 18:10                                                                                                                                 ` Stefan.Lucks
2013-04-07 18:23                                                                                                                                   ` Dmitry A. Kazakov
2013-04-05 20:38                                                                                                                             ` Stefan.Lucks
2013-04-05 14:36                                                                                                                 ` Dmitry A. Kazakov
2013-04-05 15:16                                                                                                                   ` Stefan.Lucks
2013-04-05 16:29                                                                                                                     ` Dmitry A. Kazakov
2013-04-05 19:55                                                                                                                       ` Stefan.Lucks
2013-04-06  1:45                                                                                                                         ` Randy Brukardt
2013-04-06  7:54                                                                                                                         ` Dmitry A. Kazakov
2013-04-07 18:17                                                                                                                           ` Stefan.Lucks
2013-04-07 18:28                                                                                                                             ` Dmitry A. Kazakov
2013-04-08  7:48                                                                                                                               ` Stefan.Lucks
2013-04-08  8:59                                                                                                                                 ` Dmitry A. Kazakov
2013-04-08 15:35                                                                                                                                   ` Stefan.Lucks
2013-04-08 19:08                                                                                                                                     ` Dmitry A. Kazakov
2013-04-09  7:18                                                                                                                                       ` Stefan.Lucks
2013-04-09  8:17                                                                                                                                         ` Dmitry A. Kazakov
2013-04-09 15:20                                                                                                                                           ` Stefan.Lucks
2013-04-09 16:15                                                                                                                                             ` Dmitry A. Kazakov
2013-04-09 22:59                                                                                                                                             ` Randy Brukardt
2013-04-09 22:57                                                                                                                                           ` Randy Brukardt
2013-04-10  7:30                                                                                                                                             ` Dmitry A. Kazakov
2013-04-10  8:00                                                                                                                                             ` Root_String'Class? (Was: Is this expected behavior or not) Jacob Sparre Andersen
2013-04-10 21:48                                                                                                                                               ` Randy Brukardt
2013-04-09 22:53                                                                                                                                     ` Is this expected behavior or not Randy Brukardt
2013-04-09 22:45                                                                                                                                   ` Randy Brukardt
2013-04-10  7:37                                                                                                                                     ` Dmitry A. Kazakov
2013-04-10 22:15                                                                                                                                       ` Randy Brukardt
2013-04-11  7:33                                                                                                                                         ` Dmitry A. Kazakov
2013-04-11 22:37                                                                                                                                           ` Randy Brukardt
2013-04-12  7:47                                                                                                                                             ` Dmitry A. Kazakov
2013-04-13  0:26                                                                                                                                               ` Randy Brukardt
2013-04-13  0:35                                                                                                                                               ` Randy Brukardt
2013-04-13  7:07                                                                                                                                                 ` Dmitry A. Kazakov
2013-04-06  1:38                                                                                                                       ` Randy Brukardt
2013-04-06  1:20                                                                                                               ` Randy Brukardt
2013-04-06  5:20                                                                                                                 ` Usefulness of OOP (was Is this expected behavior or not) J-P. Rosen
2013-04-06 10:31                                                                                                                   ` Dmitry A. Kazakov
2013-04-06 18:43                                                                                                                     ` Georg Bauhaus
2013-04-07  7:00                                                                                                                 ` Is this expected behavior or not Dmitry A. Kazakov
2013-04-09 23:24                                                                                                                   ` Randy Brukardt
2013-04-10  8:20                                                                                                                     ` Dmitry A. Kazakov
2013-04-10 22:07                                                                                                                       ` Randy Brukardt
2013-04-11  7:59                                                                                                                         ` Dmitry A. Kazakov
2013-04-11 11:10                                                                                                                           ` Georg Bauhaus
2013-04-11 13:49                                                                                                                           ` J-P. Rosen
2013-04-11 15:07                                                                                                                             ` Dmitry A. Kazakov
2013-04-12  4:39                                                                                                                               ` J-P. Rosen
2013-04-12  8:00                                                                                                                                 ` Dmitry A. Kazakov
2013-04-12  9:09                                                                                                                                   ` J-P. Rosen
2013-04-12 17:00                                                                                                                                     ` Jeffrey Carter
2013-04-11 23:02                                                                                                                           ` Randy Brukardt
2013-04-12  8:17                                                                                                                             ` Dmitry A. Kazakov
2013-04-12  9:41                                                                                                                               ` Georg Bauhaus
2013-04-12 11:46                                                                                                                                 ` Dmitry A. Kazakov
2013-04-13 17:38                                                                                                                                   ` Georg Bauhaus
2013-04-13  0:22                                                                                                                               ` Randy Brukardt
2013-04-13  6:49                                                                                                                                 ` Dmitry A. Kazakov
2013-04-16  1:41                                                                                                                                   ` Randy Brukardt
2013-04-16  8:03                                                                                                                                     ` Dmitry A. Kazakov
2013-04-16 22:57                                                                                                                                       ` Randy Brukardt
2013-04-17  7:18                                                                                                                                         ` Dmitry A. Kazakov
2013-04-17  9:23                                                                                                                                           ` Georg Bauhaus
2013-04-17  9:57                                                                                                                                             ` Dmitry A. Kazakov
2013-04-17 19:38                                                                                                                                               ` Georg Bauhaus
2013-04-18 11:52                                                                                                                                                 ` Dmitry A. Kazakov
2013-04-19  2:16                                                                                                                                                   ` Randy Brukardt
2013-04-19  7:39                                                                                                                                                     ` Dmitry A. Kazakov
2013-04-19  9:07                                                                                                                                                   ` Georg Bauhaus
2013-04-19  9:11                                                                                                                                                     ` Georg Bauhaus
2013-04-19 12:09                                                                                                                                                     ` Dmitry A. Kazakov
2013-04-19 22:14                                                                                                                                                       ` Randy Brukardt
2013-04-20  6:39                                                                                                                                                         ` Dmitry A. Kazakov
2013-03-19  0:38                                                       ` Shark8
2013-03-19  8:53                                                         ` Dmitry A. Kazakov
2013-03-16 20:45                                             ` Robert A Duff
2013-03-16  9:29                                           ` Georg Bauhaus
2013-03-16 20:49                                             ` Robert A Duff
2013-03-14 22:41                             ` Florian Weimer
2013-03-12 23:21           ` Randy Brukardt
2013-03-12 23:14       ` Randy Brukardt
2013-03-11 20:43   ` Anh Vo
2013-03-11 22:32     ` Randy Brukardt
2013-03-11 22:38     ` Robert A Duff
2013-03-12  9:17   ` Dmitry A. Kazakov
2013-03-13  0:10     ` Shark8
replies disabled

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