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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,103b407e8b68350b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-20 18:10:42 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!wn11feed!worldnet.att.net!64.154.60.72!cyclone2.usenetserver.com!news.webusenet.com!news01.optonline.net!news4.srv.hcvlny.cv.net.POSTED!not-for-mail From: "Hillel Y. Sims" Newsgroups: comp.lang.ada References: <1041908422.928308@master.nyc.kbcfp.com> <1041997309.165001@master.nyc.kbcfp.com> <1042086217.253468@master.nyc.kbcfp.com> <1042477504.547640@master.nyc.kbcfp.com> <1042651417.215661@master.nyc.kbcfp.com> <1042743579.1165@master.nyc.kbcfp.com> <1042824191.538184@master.nyc.kbcfp.com> <_VkW9.266404$FT6.43771824@news4.srv.hcvlny.cv.net> Subject: Re: Anybody in US using ADA ? One silly idea.. Organization: Phat Basset Novelties, www.phatbasset.com MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: Date: Tue, 21 Jan 2003 02:10:37 GMT NNTP-Posting-Host: 67.86.54.13 X-Trace: news4.srv.hcvlny.cv.net 1043115037 67.86.54.13 (Mon, 20 Jan 2003 21:10:37 EST) NNTP-Posting-Date: Mon, 20 Jan 2003 21:10:37 EST Xref: archiver1.google.com comp.lang.ada:33263 Date: 2003-01-21T02:10:37+00:00 List-Id: "Dmitry A. Kazakov" wrote in message news:b0e5vu$ognn6$1@ID-77047.news.dfncis.de... > Hillel Y. Sims wrote: > [templated C++ sort() is faster than qsort()] > > This is a wrong comparison. A correct one would be an instance of a generic > subroutine vs. an inlined subroutine and, note, when the type is statically > known. sort() vs. sort_ints()? In that case the performance should really be exactly the same (since as you say, it really *is* to a large extent just a bunch of text substitution :-). The benefit is that you don't need to rewrite or copy/paste the code over and over for each unique type, the compiler does it automatically (while maintaining full type safety, unlike dumb macros) -- and better yet, when you fix a bug in the generic version, it is immediately fixed for all instantiations automatically (vs. sort_ints(), sort_floats(), sort_strings(), sort_xyz()) > > How do you compare gotos to generics? Generics do not destroy structured > > code. I just don't understand the analogy. > > They are as chaotic as gotos. They destroy the type structure of the program > as gotos do the control flow. Hyman Rosen gave us a brilliant example of > generic code for handling dimensioned values. But get a programmer from > street and ask him why and how it works. Programming should be as simple as > tooth powder. (:-)) No argument that some crazy stuff can be done that is really difficult to interpret by humans. I'm not sure you've really made the case "generics considered harmful" though yet.. > > It can actually help. For example, in the case of the standard C++ > > container class std::vector -- there can be a specialization defined (I > > forget if it is mandated by the Standard, but it is possible anyhow) for > > all std::vector such that they are inherited from std::vector > > with just the necessary casts thrown in by the compiler (inline). This can > > eliminate a large amount of unnecessary code bloat for all instantiations > > of vectors of pointer types. > > With pointer types we do not need generics at all, because all pointers are > of some predictable size. However, full type safety is maintained without requiring programmers to manually do (error-prone) casting. >Then it is not the actual problem. The problem is > that std::vector is not a type, so even std::vector* cannot exist. > Sure it can: template void f(std::vector* pVec) { pVec->clear(); //etc... } :-) hys -- (c) 2003 Hillel Y. Sims hsims AT factset.com