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!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: class wide iterable (and indexable) Date: Sat, 5 Jan 2019 03:21:53 -0600 Organization: JSA Research & Innovation Message-ID: References: <2a6929c5-72fa-4d84-953a-44ea4597ab38@googlegroups.com> Injection-Date: Sat, 5 Jan 2019 09:21:54 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="31802"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 X-RFC2646: Format=Flowed; Response Xref: reader01.eternal-september.org comp.lang.ada:55193 Date: 2019-01-05T03:21:53-06:00 List-Id: "Dmitry A. Kazakov" wrote in message news:q0n6av$1tqs$1@gioia.aioe.org... ... > In real programs dispatch is rare, thus there is no overhead. This is probably true, but then interfaces are even more useless (they provide nothing that could possibly be of value other than dispatch!). > I don't know which overhead Randy meant, though. Maybe, space overhead? > That is not nearly close to what generics produce in GNAT... Dispatching is very expensive for interfaces, in that some form of search is needed. (Note: I have no idea how GNAT implements them exactly.) It might be possible to do some sort of link-time assignment of interface identifiers and link-time tag construction to avoid some of that cost (at the cost of a lot of space), but that would be such a complex and unusual project (conventional linkers don't support anything like that) that I've always considered it impraactical. ... > No, interfaces cannot contain common code except for class-wide one. Is > that what Randy meant about overhead? Not really. My main point is that you'll never have more than one concrete instance of a generic interface in any individual program (certainly not of an interface like that of a container), so all you're doing is paying a lot of overhead to use dispatching to that one concrete instance. You're better off (esp. in non-Janus/Ada compilers) using a formal package for that, as there's no runtime overhead involved. Even in Janus/Ada, there isn't much extra overhead (a formal package is just the formal descriptor block for the appropriate instance, so the overhead is the same as any normal generic). Note: I mean one concrete type, there might be many objects of that type. But it doesn't make sense to use bounded and indefinite containers at the same time for the same element type. So an interface buys you very little. As Dmitry noted, you'd still have to pass the interface into a generic if you want any shared code. But you could have just passed the instance of the container into the generic and get the same sort of sharing. Dmitry is of course an all-interface all the time sort of guy. All I see from that is a vast amount of typing to get nothing in particular in return. [But I'm not much of a fan of OOP, either; the big advantage of OOP is requiring few recompiles when adding features. That was a big deal in 1990, but it hardly matters today. (I can recompile the entirety of Janus/Ada - 250,000 lines - in 15 minutes or so. Why try to save compiles?) And for that, you get to type dozens and dozens of declarations to do anything. While the supposedly terrible case statement solution gives you case completeness checks, variant checks, and essentially has no more chance of failure (and costs a lot less, and keeps all of the similar code together rather that scattering it about to every different kind of object).] Randy.