From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: class wide iterable (and indexable) Date: Fri, 4 Jan 2019 09:43:07 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <2a6929c5-72fa-4d84-953a-44ea4597ab38@googlegroups.com> NNTP-Posting-Host: i065DRYuysvTI4qVnaNkyg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.3 Xref: reader01.eternal-september.org comp.lang.ada:55187 Date: 2019-01-04T09:43:07+01:00 List-Id: 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