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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Why forbid local generic instantiations? Date: Fri, 25 Jan 2019 17:36:33 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <100ce3ee-71f7-46c7-a24c-dc9c0d280c4f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 25 Jan 2019 16:36:35 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="2ea0abe79bdaecdebed2a2d2e43456f4"; logging-data="10231"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+taBUhZn8+SsFwN4AxivOE4DkSoVxwskY=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 Cancel-Lock: sha1:VtfXaEALgJXHbu4/mA+0E2eKFCM= In-Reply-To: <100ce3ee-71f7-46c7-a24c-dc9c0d280c4f@googlegroups.com> Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:55369 Date: 2019-01-25T17:36:33+01:00 List-Id: On 1/25/19 10:43 AM, joakimds@kth.se wrote: > > 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 isn't bad practice. Mostly such rules are premature optimization. Are there rules against regular pkgs in such places? There's no difference. It makes perfect sense for things to be declared in the smallest scope in which they're needed. This is true of anything, not just pkgs. A pkg in a subprogram is elaborated every time the subprogram is called. If the elaboration of a specific pkg is expensive and timing requirements are tight, it might make sense to move that pkg to a larger scope. But a general rule against them for "efficiency" doesn't make sense. Limiting it to pkgs that are generic instantiations makes less sense. Perhaps such people don't know that instantiation takes place during compilation and has no run-time impact. As a 1st-order approximation, anything the "C++ Community" does should be avoided. -- Jeff Carter "I was hobbling along, minding my own business, all of a sudden, up he comes, cures me! One minute I'm a leper with a trade, next minute my livelihood's gone! Not so much as a 'by your leave!' You're cured, mate. Bloody do-gooder!" Monty Python's Life of Brian 76