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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,30fad28eb8886cca X-Google-Attributes: gid103376,public From: blaak@mda.ca (Ray Blaak) Subject: Re: parameterless generics? Date: 1996/07/11 Message-ID: <4s4sns$nl4@map.mda.ca>#1/1 X-Deja-AN: 167942385 references: <4s48k9$3be$1@mhafn.production.compuserve.com> content-type: text/plain; charset=us-ascii organization: Macdonald Dettwiler & Associates mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-07-11T00:00:00+00:00 List-Id: Brian Gilbert <71413.1453@CompuServe.COM> writes: >Does anybody have a reason to use a generic (package or >subprogram) without a parameter? The language (Ada 83 at least) >seems to allow it, but everytime the generic is instantiated it >would produce an identical copy. Comments? I find it useful primarily to give distinct types that cannot legally be converted to each other. generic package Element is type Object is private; procedure Operation (On_The_Object : in out Object); private type Object is ...; end Element; package Node is new Element; package Symbol is new Element; Node.Object and Symbol.Object cannot be converted from one to the other, whereas they could if derived from a common type. Another possible reason is to make functionality "active" only when you need it. Consider: package Entity is type Object is private; procedure Low_Impact_Operation (On_The_Object : in out Object); generic package Fancy_Processing_Involving_A_Huge_Link_Enclosure is procedure Do_It_At_Your_Own_Risk (To_Me : in out Object); end Fancy_Processing_Involving_A_Huge_Link_Enclosure; end Entity; It could be that one application (say offline report generation) only needs a few features and a small link enclosure. The real system might be involved in a complex architecture with a large link enclosure. By having the extra operations in a generic, there should be no executable code generated for it until instantiation. This would be dependent on how you wrote the generic and how the compiler implements generics. Cheers, Ray Blaak blaak@mda.ca