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: Why forbid local generic instantiations? Date: Fri, 25 Jan 2019 15:34:38 -0600 Organization: JSA Research & Innovation Message-ID: References: <100ce3ee-71f7-46c7-a24c-dc9c0d280c4f@googlegroups.com> Injection-Date: Fri, 25 Jan 2019 21:34:39 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="23731"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader01.eternal-september.org comp.lang.ada:55373 Date: 2019-01-25T15:34:38-06:00 List-Id: wrote in message news:100ce3ee-71f7-46c7-a24c-dc9c0d280c4f@googlegroups.com... ... >Why is it considered bad practise to use local generic instantiations? >Within the >C++ Community, limiting the use of templates doesn't seem an issue. On the >contrary, going all in with template metaprogramming is the norm. It's not bad practice *in general*, but it might be for particular generics: (1) In Ada 95, extensions had to be at the same accesibility level as their parent, which meant that virtually all generics containing tagged types had to be instantiated at library-level. Ada 2005 lifted that restriction, but it does have a cost in terms of extra checks and substantially more expensive tags. So it could be better to instantiate those generics at library-level (even though they can be instantiated locally). (2) Most compilers (not Janus/Ada or early Rational compilers) make a copy of the generic when it is instantiated. Thus, it's usually better to instantiate a generic once at library-level and have all of the clients use that single instance rather than making multiple copies of the same code. (Automatically sharing code is hard for compilers to do.) Even if usage would allow a more local instance. Even compilers like Janus/Ada that use code sharing generate some code at the point of the instantiation, so you might want to avoid instantiating the same generic multiple times. (3) Ada requires Legality Rules to be rechecked for an instance, so its possible that some generics cannot be instantiated other than at library-level (because accessibility checks or various other rules). Even so, I don't know of any reason to avoid local instances in general. In particular, you probably want to instantiate Unchecked_Conversion and possibly Unchecked_Deallocation locally. And I'd say that's true about any small generic. In any case, just because some style checker has a rule, that doesn't mean it is a good idea to follow it. Lots of people's Ada style guides (not mine, of course ;-) have poorly considered rules in them. People who build style checkers implement every rule that someone might want, whether or not it is good idea is not their concern. Randy.