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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,43f6bd9b498b66d0 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!q78g2000hsh.googlegroups.com!not-for-mail From: Eric Hughes Newsgroups: comp.lang.ada Subject: Re: default formal parameters in generic declarations Date: Wed, 5 Mar 2008 13:08:49 -0800 (PST) Organization: http://groups.google.com Message-ID: <0078161e-64c7-4fa8-9794-b840d855a88b@q78g2000hsh.googlegroups.com> References: <9b3bac4d-5ae1-4a1b-a81e-9aa9ae1843e0@e31g2000hse.googlegroups.com> NNTP-Posting-Host: 166.70.57.218 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1204751330 17396 127.0.0.1 (5 Mar 2008 21:08:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 5 Mar 2008 21:08:50 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q78g2000hsh.googlegroups.com; posting-host=166.70.57.218; posting-account=5RIiTwoAAACt_Eu87gmPAJMoMTeMz-rn User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20188 Date: 2008-03-05T13:08:49-08:00 List-Id: On Mar 4, 11:43 am, "Randy Brukardt" wrote: > Looking back at the old > minutes, we had a straw poll where about half of the people present thought > that this feature was not important enough. That's a pretty significant > number I can understand why so many people did not understand the significance of this feature. I know I would not have then. It wasn't until just the last two years or so that I've done any really significant generic programming in C++. Let me begin to rectify that deficiency in understanding its significance. The real difficulty with not have package defaults begins the second layer of generic instantiation, not the first. For just one layer (by that I mean a simple instantiation of a generic) it's certainly easy enough to put in a default manually. But what then if the package in which this happens is itself generic, and, furthermore, incurs a dependency of this instantiation on its own formal parameters? This is the completely typical case, to pick an example, for a generic package "A" that's configurable with a storage pool. Another generic package "B" should (in most cases), as a matter of information hiding, also have a storage pool parameter of its own that it forwards to package "A" at its instantiation, but should also allow a different storage pool for "A". (I don't know why you'd want this insofar as storage pools go, but they're just the example parameter here.) Without a default formal parameter, there is no way to get both of the following desiderata simultaneously: 1. Forwarding of the "B" parameter to "A" and elision of a duplicate parameter when these are the same. 2. Ability to override the forward and specify a separate parameter in "B" for use in "A". You can get 1 by just hard-coding the instantiation parameter for "B", but that eliminates 2. You can get 2 by using an extra parameter in "B", but that eliminates the second half of 1. Even with just two layer of instantiation this is feasible, but, in the phrase I used earlier, "horribly klunky" (particularly with non- linear references). So here's the biggest problem: You cannot get simultaneously both arbitrarily deep layering and concision in formal parameters for ordinary usage. Without defaults, every single ordinary usage has the same notational complexity as an arbitrary usage in full generality. This severely limits the practical utility of generic programming in Ada to simple cases. And I say that anything that limits the depth of abstraction layering is a _prima facie_ bad thing. It breaks information hiding in a bad way. As a coda, I wish to add that this practice is not hypothetical. The sophistication of some of the generic (template) programming in the Boost C++ library is excellent and worth imitating.