comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: class wide iterable (and indexable)
Date: Fri, 4 Jan 2019 09:43:07 +0100
Date: 2019-01-04T09:43:07+01:00	[thread overview]
Message-ID: <q0n6av$1tqs$1@gioia.aioe.org> (raw)
In-Reply-To: f62bb15c-ebd2-45f7-b591-796a1957e99a@googlegroups.com

On 2019-01-04 01:00, George Shapovalov wrote:

>> Besides, interfaces are (nearly) useless (and especially so for this sort of
>> usage, where some part has to be generic). They add a lot of runtime
>> overhead that doesn't actually get used in real programs.
> Really?

I am using interfaces extensively and in real programs. (:-))

> I did not consider this. I thought there would be no extra overhead, as the compiler should be able to select appropriate constructs as needed and optimize away with higher -OX.

In real programs dispatch is rare, thus there is no overhead. I don't 
know which overhead Randy meant, though. Maybe, space overhead? That is 
not nearly close to what generics produce in GNAT...

>> Perhaps if Ada allowed multiple controlling parameters of different tagged
>> types, then there might be more use.
> Funny that you mention this one. That was my thought exactly at one (completely unrelated) point - that unlike most other languages, Ada has the syntax that could naturally allow multiple controlling parameters, and that could be a really powerful type composition feature..

Huh, it would render generics useless! That would sadden a lot of 
people... (:-))

Alas, nobody knows how to make multiple dispatch safe while usable in 
independent packages. The case is when you derive from the types of the 
hierarchies in independently developed packages.

> A pity this was not done so, that would be a fun feature. But then I do realize that it takes a special kind of thought organization (more pure math than typical procedural idiom most programmers follow) for the developer to feel comfortable with such a feature. With most other common languages not having even a provision to formulate such a structure, most developers would be at a loss to comprehend what is even proposed in the standard I am afraid (at least from what I could observe).

Huh, most developers are at loss with generic instances they produce.

> So I can see why this was not seriously considered. Plus that would give a huge potential for abuse - just think of all the possible combinations multiplying complexity, having to turn simple dispatch tables into multidimensional (and very sparse) arrays..

No. However in the case of multiple dispatch you rarely can inherit 
safely. You would be required to override a lot, so the table would not 
be sparse.

>> But with the existing Ada rules,
>> interfaces can only be useful if the profiles are fixed (non-generic) and
>> are still reusable -- that doesn't happen that often.

Combination of interfaces and generics is the only way to handle many 
situations in practice. Actually it is a very frequent pattern when a 
base type is a formal parameter of some generic used to derive from it 
while adding implementations.

> Besides the optimization issues, which are invisible to end user and often are not so critical, I fail to see how generics would affect logical structure of the program in this case.

As all preprocessors generics tend to destroy any logic and every design 
by muddying mapping of the program types and modules to the 
problem-space entities.

> Besides linking various type hierarchies together, interfaces are good for containing common code that does not care about specific data storage details.

No, interfaces cannot contain common code except for class-wide one. Is 
that what Randy meant about overhead? This is another Ada problem that 
multiple inheritance is not fully supported. If it were, you could 
indeed have common code in the form of inherited bodies. But you cannot. 
Thus to overcome this language design fault we use the generic pattern I 
mentioned above:

    generic
       type Base is interface ...;
    package Poor_Mans_Inheritance;
       type Instance is new Base with ...;
       overriding procedure Inherit_Me_Please (X : in out Instance);
    end Poor_Mans_Inheritance;

    type My_Type_I_Cannot_Use_Yet is new Base with ...;
    package Generic_Mess is
       new Poor_Mans_Inheritance (My_Type_I_Cannot_Use_Yet);
    type My_Type is new Generic_Mess.Instance with null record;

> How generics complicate the issue?

It is hideous.

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


  reply	other threads:[~2019-01-04  8:43 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-02 15:48 class wide iterable (and indexable) George Shapovalov
2019-01-02 17:39 ` Simon Wright
2019-01-02 18:11   ` George Shapovalov
2019-01-03  8:52     ` Simon Wright
2019-01-03  9:30       ` George Shapovalov
2019-01-03 16:45         ` Jeffrey R. Carter
2019-01-04  4:32       ` Shark8
2019-01-05  9:03         ` Randy Brukardt
2019-01-03 22:56     ` Randy Brukardt
2019-01-04  0:00       ` George Shapovalov
2019-01-04  8:43         ` Dmitry A. Kazakov [this message]
2019-01-04 12:20           ` George Shapovalov
2019-01-05 23:29             ` Jere
2019-01-05 23:50               ` Jere
2019-01-06  9:34                 ` George Shapovalov
2019-01-06 10:19                   ` Dmitry A. Kazakov
2019-01-06 11:30                     ` George Shapovalov
2019-01-06 12:45                       ` Dmitry A. Kazakov
2019-01-06 13:18                         ` George Shapovalov
2019-01-06 14:13                           ` Dmitry A. Kazakov
2019-01-06 16:33                             ` George Shapovalov
2019-01-06 18:29                               ` George Shapovalov
2019-01-06 20:32                                 ` Dmitry A. Kazakov
2019-01-06 21:47                                   ` George Shapovalov
2019-01-07  9:37                                     ` Niklas Holsti
2019-01-07 16:24                                       ` George Shapovalov
2019-01-06 20:18                               ` Dmitry A. Kazakov
2019-01-06 21:58                                 ` George Shapovalov
2019-01-07  8:28                                   ` Dmitry A. Kazakov
2019-01-05  9:21           ` Randy Brukardt
2019-01-05 10:07             ` Dmitry A. Kazakov
2019-01-05 18:17               ` George Shapovalov
2019-01-05 20:07                 ` Simon Wright
2019-01-05 20:41                   ` George Shapovalov
2019-01-07 21:07               ` Randy Brukardt
2019-01-08  9:51                 ` Dmitry A. Kazakov
2019-01-08 19:25                   ` Björn Lundin
2019-01-08 23:26                   ` Randy Brukardt
2019-01-09 17:06                     ` Dmitry A. Kazakov
2019-01-09 23:38                       ` Randy Brukardt
2019-01-10  8:53                         ` Dmitry A. Kazakov
2019-01-10 22:14                           ` Randy Brukardt
2019-01-11  9:09                             ` Dmitry A. Kazakov
2019-01-14 22:59                               ` Randy Brukardt
2019-01-15  9:34                                 ` Dmitry A. Kazakov
2019-01-18 15:48                                   ` Olivier Henley
2019-01-18 16:08                                     ` Dmitry A. Kazakov
2019-01-18 16:29                                       ` Olivier Henley
2019-01-18 16:54                                         ` Dmitry A. Kazakov
2019-01-18 17:31                                           ` Olivier Henley
2019-01-18 18:51                                             ` Shark8
2019-01-18 20:09                                             ` Dmitry A. Kazakov
2019-01-21 23:15                                     ` Randy Brukardt
2019-01-22  8:56                                       ` Dmitry A. Kazakov
2019-01-22 22:00                                         ` Randy Brukardt
2019-01-23  8:14                                           ` Dmitry A. Kazakov
2019-01-22 17:04                                       ` Jeffrey R. Carter
2019-01-22 22:02                                         ` Randy Brukardt
2019-01-23 18:00                                           ` Jeffrey R. Carter
2019-01-23 20:14                                           ` Shark8
2019-01-23 22:47                                             ` Randy Brukardt
2019-01-24 17:11                                               ` Dmitry A. Kazakov
2019-01-28 15:54                                               ` Shark8
2019-01-28 17:23                                                 ` Dmitry A. Kazakov
2019-01-08 18:32                 ` G. B.
2019-01-05 17:05             ` Jeffrey R. Carter
2019-01-05 20:18               ` Dmitry A. Kazakov
2019-01-05 21:09               ` Shark8
2019-01-06 10:11                 ` Jeffrey R. Carter
2019-01-05 20:46             ` Shark8
2019-01-06  9:43               ` Dmitry A. Kazakov
2019-01-26 22:11 ` George Shapovalov
2019-01-26 22:14   ` George Shapovalov
  -- strict thread matches above, loose matches on Subject: below --
2019-01-29  7:45 Randy Brukardt
2019-01-29 19:34 ` Niklas Holsti
2019-01-29 20:26   ` Dmitry A. Kazakov
replies disabled

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