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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9cccf6ef6149fdaa X-Google-Attributes: gid103376,public From: Hyman Rosen Subject: Re: Ada Date: 2000/01/04 Message-ID: #1/1 X-Deja-AN: 568171213 Sender: hymie@calumny.jyacc.com References: <38620350.48F8FC08@gecm.com> <83tohh$q2s$1@nnrp1.deja.com> <83u8l0$5i5$1@nnrp1.deja.com> <84rd2f$snm$1@nntp3.atl.mindspring.net> <84rphr$ql5$1@nntp8.atl.mindspring.net> X-Complaints-To: abuse@panix.com X-Trace: news.panix.com 946997125 4407 209.49.126.226 (4 Jan 2000 14:45:25 GMT) Organization: PANIX Public Access Internet and UNIX, NYC NNTP-Posting-Date: 4 Jan 2000 14:45:25 GMT Newsgroups: comp.lang.ada Date: 2000-01-04T14:45:25+00:00 List-Id: Richard D Riehle writes: > Ada generics (templates)are always compiled before they are > "included" by the client. This is a function of the Ada library > model. The instantiation is permitted only after the successful > compilation of the generic unit. This puts type checking a little > closer to the origination of the generic. > > If I read the C++ literature correctly, C++ templates are expected > to be "full expansion" units. Ada permits a template to be instantiated > in other forms to conserve memory. Some compilers support this. You have not read the literature correctly, or you have not read the correct literature :-) C++ templates can be (according to the standard, but not yet in reality) separately compiled, and many errors within the template can be caught before instantiation. You are correct in that it is unlikely that a C++ will offer anything but the full-expansion style of template instantiation. > Ada has more formats for generic formal parameters. This has its > advantages and may sometimes have disadvantages. The designer needs > to learn more idioms of the language. Once having learned those idioms, > more options for template design are available. C++ has essentially *no* format for its generic formals, which are types, templates, or constants. I think that allows C++ to achieve the same things with its templates that Ada can. > Ada permits but does not require as much overloading of operators > as one needs in a C++. This is useful when one is creating templates > for simple scalar and numeric types. It does simplify the templates > for those types. Actually, in this case, the Ada model is somewhat > an improvement over C++. Of course, a C++ advocate may answer that > the word "class" may be used for a built-in type, but this still falls > short of the Ada model for range constraints and other rules of > scalar types. Well, C++ doesn't have range constraints and subtypes (which is too bad), so it can hardly overload on them. But it does have enumerations, and those are fully overloadable. But C++ doesn't have attributes, so one can't write a generic wrap-around successor function, for example, so there, I've found an example for you :-) > Ada is more complicated when creating templates in which an entire > package is a generic formal parameter. C++ is very straightfoward > in this regard. The consequence is that this powerful feature of > Ada is often ignored by component designers. In time, as Ada > practitioners become more comfortable with its capabilities, we should > see more use of it. Meanwhile, C++ seems much easier when one needs > one of more classes as generic formal parameters. I hold that a C++ class is more-or-less equivalent to an Ada package, so a generic formal package in Ada would simply correspond to a generic formal class in C++.