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,FREEMAIL_FROM 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-31 07:02:18 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshosting.com!news-xfer1.atl.newshosting.com!uunet!dca.uu.net!ash.uu.net!spool0902.news.uu.net!not-for-mail Date: Fri, 31 Jan 2003 10:02:15 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3b) Gecko/20030130 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Anybody in US using ADA ? One silly idea.. References: <1043680098.61106@master.nyc.kbcfp.com> <3afc3v4uur2kvd53v4ul18b5npjfm188o3@4ax.com> <1043773909.385612@master.nyc.kbcfp.com> <1043855067.848326@master.nyc.kbcfp.com> <3OXZ9.85359$Ve4.6306@sccrnsc03> <1043880843.44251@master.nyc.kbcfp.com> <1043938782.244443@master.nyc.kbcfp.com> <25ji3v8n915cnnnaqpjvm4f7i01a66r9pf@4ax.com> <1043949507.331484@master.nyc.kbcfp.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1044025336.3067@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1044025337 10000 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:33641 Date: 2003-01-31T10:02:15-05:00 List-Id: Dmitry A. Kazakov wrote: > Of course no. Generics are unable to make String a subtype of > Unbounded_String. Ada generics, which labor under the restriction of needing to specify things about the types on which they operate, not C++ templates, which work as long as used operations are supported. > Any OO language does this. Ada does not, C++ does not, I don't know for sure but I think Eiffel does not. Smalltalk, maybe? > Only if it is inherited. Why? Since you're converting, what possible relevance is there to requiring that the operation be present in both types? > Ada does this. Really? It does convert-in/convert-out of different types? I've never seen that before. Can you show me sample code? > Where you see a new concept? Circle and Ellise are two different > types. So if you want make an Ellipse out of a Circle you must convert > it. In Ada such conversions are called view-conversions. As I said, no one else sees it this way. The normal OO view of things is that if type B inherits from type A, then an object of type B is also of type A. No conversion is required - the object is already all of its base types. > Now tell me why for SetAxis : Circle x R x R -> Circle it is not > reasonable to throw an exception? Do not you see that NN vs. Float > is same as Circle vs. Ellipse? It is reasonable to do so if you must have your Circle put into places that expect modifiable Ellipses. But I believe the general feeling is that having subtypes which restrict the legality of parent operations in this way is not good design. I suppose Eiffel fans will disagree with this, since they seem to love the idiom of inheriting operations but only allowing the new subtype as an argument. Shudder. Java uses this style as well, with all sorts of operations in subtypes throwing not-implemeneted exceptions. > Sort of: > template double sine () { return X; } > // Works pretty well, as long X is close to zero Actually, C++ template parameters can't be doubles, but why is this any worse, or different, than #include #include struct SineInterface { virtual double operator()(double) const = 0; }; struct SmallSine : SineInterface { double operator()(double x) const { return x; } }; struct RealSine : SineInterface { double operator()(double x) const { return std::sin(x); } }; void UsesSine(const SineInterface &si1, const SineInterface &si2) { for (double x = 0; x < 1e-5; x += 1e-7) std::cout << x << ' ' << si1(x) << ' ' << si2(x) << '\n'; } int main() { UsesSine(SmallSine(), RealSine()); }