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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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-17 10:53:26 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!newsfeed2.earthlink.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: Anybody in US using ADA ? One silly idea.. Date: Fri, 17 Jan 2003 11:02:39 -0800 Organization: AdaWorks Software Engineering Message-ID: <3E28534F.DD4016C3@adaworks.com> 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> Reply-To: richard@adaworks.com NNTP-Posting-Host: 3f.bb.81.33 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 17 Jan 2003 18:53:25 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:33155 Date: 2003-01-17T18:53:25+00:00 List-Id: Hyman Rosen wrote: > No, that is the price of using Ada generics. In C++, because of > specialization, you can have all of those things. Specialization > means that you can have entirely different code for a generic > instantiation based on the parameters; in Ada you cannot do this. > Andrei Alexandrescu's _Modern C++ Design_ is the best exposition > of these kind of techniques. The attitude in this kind of > programming is that using a specifc type instead of a generic > parameter is a lot like using a magic number in the code. I have read Alexandrescu's discussion of this interesting feature of C++. His is probably the first good book on C++ design I have seen. It almost makes the language look reasonable. :-) Note the smiley, Hyman. Here is a generic in Ada, which while not identical to the C++ model, does permit combining specialization with genericity and which has turned out to be quite useful for certain kinds of problems. When combined with some of the other examples Mr. Findlay and I have posted, it becomes a powerful tool for designing complex solutions. ================================================ generic type Item is abstract tagged private; package Generic_Abstract_Type is type Starting_Type is abstract new Item with private; -- override inherited methods from Item procedure Make (The_Item : Starting_Type); -- extend with additional methods -- including, optionally, abstract methods private type Starting_Type is abstract new Item with null record; end Generic_Abstract_Type; ============================================== The generic formal parameter could also have been something such as, generic type Item is abstract new T with private; type Reference is access all Item'Class; package Generic_T_Derivation is ... end Generic_T_Derivation; Many more variations are possible. We can combine specialization with genericity. In this example, we also include a generic formal access type so we can do indirect access operations at the classwide level. Richard Riehle