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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Parameterless generic instance in place of opaque type instance Date: Sun, 28 Jul 2013 09:02:22 +0200 Organization: Ada @ Home Message-ID: References: NNTP-Posting-Host: ds8m8HfAx594C0h4s/JFyA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:16571 Date: 2013-07-28T09:02:22+02:00 List-Id: Le Sun, 28 Jul 2013 08:36:36 +0200, Yannick Duch=C3=AAne (Hibou57) = a =C3=A9crit: > The Ada 95 Q&S Guide mention this pattern, and seems to have no more t= o = > say about it, not more than what is obvious: > http://www.adaic.org/resources/add_content/docs/95style/html/sec_8/8-3= -5.html > They call this pattern, =E2=80=9CGeneric Abstract Data Object=E2=80=9D= . An idea, and there may have missed another interesting variation, = something with mixed properties from a GADO and an ADT. Say a GADO still defines an ADT, with an unknown discriminant, so that i= t = cannot be instantiated without initialization. What the private declares= , = is just an access type to a deferred type (defined in the body). The bod= y = defines an instance of the type it fully defines. The package offers a = single function returning an (opaque) access to this unique and = per=E2=80=91paquage instance, instance. The function could be named = `Instance_Reference`, to clearly show it's always the same behind, howev= er = a new distinct one per generic instance (not strictly a singleton, a = per=E2=80=91package singleton). This would provide some of the benefit of an ADT and some of a GADO, = together. The same as an ADT regarding the ability to pass it to a = sub=E2=80=91program, while avoiding the heap allocation (which I surely = don't = want) otherwise required with an access to a deferred type (or else an = allocation in a static pool, =E2=80=A6 not so nice for many reasons) and= avoiding = to pollute the private part of the package (I don't enjoy when the priva= te = part monopolizes 85% of a package's text). This could be named, say =E2=80=9CGeneric Abstract Singleton Data Type=E2= =80=9D, or = something like that :-D What's you feeling on that variation? -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity