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,29d8139471e3f53e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!q9g2000vbd.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Preventing type extensions Date: Fri, 24 Sep 2010 02:20:49 -0700 (PDT) Organization: http://groups.google.com Message-ID: <7f718cec-a2c5-42de-932d-4998b84df29e@q9g2000vbd.googlegroups.com> References: <87iq2bfenl.fsf@mid.deneb.enyo.de> <134q4k2ly2pf4$.17nlv1q6q5ivo.dlg@40tude.net> <4c8dec8e$0$6990$9b4e6d93@newsspool4.arcor-online.net> <8f6cceFrv2U1@mid.individual.net> <135a7dc9-3943-45e4-884b-3cc6bce3db0a@q18g2000vbm.googlegroups.com> <81799aab-a2e8-4390-8f42-abceaa5fc032@m1g2000vbh.googlegroups.com> <5c0d7798-ba09-4bd0-a28f-f1b028cce927@y3g2000vbm.googlegroups.com> <87r5gl8tky.fsf@ludovic-brenta.org> <4C9B858C.9050208@obry.net> <877hic8asm.fsf@ludovic-brenta.org> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1285320049 4620 127.0.0.1 (24 Sep 2010 09:20:49 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 24 Sep 2010 09:20:49 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q9g2000vbd.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14228 Date: 2010-09-24T02:20:49-07:00 List-Id: Ludovic Brenta wrote on comp.lang.ada: > Pascal Obry writes on comp.lang.ada: > >> Ludovic, > >>> And people not knowing Ada and thinking that the only OO language was >>> C++. =A0I totally agree with Jean-Pierre that Ada has made a very >>> important contribution to OO technology in distinguishing class-wide >>> from specific types; > >> Well this was part of Smalltalk since the beginning. Not sure Ada has >> invented anything there :) > > I do not remember anything in Smalltalk resembling class-wide types; > could you please send me an URL? I'm curious. In fact, after reading up a little bit on Smalltalk, it seems that every message sent to an object (i.e. primitive operation call) dispatches dynamically; the programmer does not seem to have a way to prevent that. As a consequence, a method that sends a message to "self" redispatches dynamically, every time. This leads to what Smalltalk programmers call "the yo-yo problem" whereby a single message (primitive operation call) can in turn cause multiple calls up and down the inheritance tree; this makes it difficult for programmers to follow the flow of control. I believe this is exactly the reason why Dmitry hates redispatching so much. Ada lets programmers choose whether a primitive operation call dispatches statically or dynamically, at the call site. To redispatch dynamically, you do a view conversion to the class-wide type; this is why class-wide types exist in the first place. Also, during code review, you can easily see distinguish dynamic calls from static calls. I believe that, if Smalltalk had class-wide types, it would be able to prevent "the yo-yo problem" just like Ada does. This "yo-yo problem" also exists in Objective-C. In C++, you can force static calls by qualifying the call, e.g. void T::method1 () { this->method2(); // dynamic redispatch: "this" is of a class-wide pointer type this->T::method2(); // static call due to explicit qualifier } -- Ludovic Brenta.