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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c0d427d5f4af20f8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: generics in Ada 83 Date: 14 Sep 2005 11:41:13 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1126617980.932226.320710@g43g2000cwa.googlegroups.com> <1126703715.202970.293880@g47g2000cwa.googlegroups.com> <1126711381.425805.248380@o13g2000cwo.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1126712473 32468 192.74.137.71 (14 Sep 2005 15:41:13 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 14 Sep 2005 15:41:13 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:4663 Date: 2005-09-14T11:41:13-04:00 List-Id: "Hyman Rosen" writes: > Jean-Pierre Rosen wrote: > > In Ada, there is no need to check legality on the expansion of the > > generic. Correct me if I'm wrong, but my understanding of templates is > > that the legality is rechecked for each instantiation. > > Well, in Ada, instantiations check the parameters for validity > against whatever contract the generic specifies for them. In C++, > the contract is implied by the usage within the template, so yes, > the legality is rechecked that way. But remember that in C++ > template instatntiation is done strictly at compile-time. As far > as the programmer is concerned, either an instantiation validly > meets the template's requirements for its parameters, or the code > fails to compile, and that is true for both languages (or at least > I think that's true for Ada). That's right. The Ada way makes it easier to understand what the contract _is_. And this implies that if you want to change the generic/template, it's easier to understand whether or not you might break any clients. (If you're writing a widely-used library, you might not have access to all existing clients, so you can't compile them to see if they break.) It also implies that the error messages are easier to understand, especially with multiple layers of templates. On the other hand, the C++ way is more powerful. - Bob