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: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,b87849933931bc93 X-Google-Attributes: gidf43e6,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: fac41,b87849933931bc93 X-Google-Attributes: gidfac41,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Exceptions as objects (was Re: What is wrong with OO ?) Date: 1997/02/07 Message-ID: #1/1 X-Deja-AN: 215103151 references: <5acjtn$5uj@news3.digex.net> <5cu43v$jkn@nntpa.cb.lucent.com> <5d93d3$nhs$1@goanna.cs.rmit.edu.au> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng Date: 1997-02-07T00:00:00+00:00 List-Id: In article <5d93d3$nhs$1@goanna.cs.rmit.edu.au>, Richard A. O'Keefe wrote: >ka@socrates.hr.lucent.com (Kenneth Almquist) writes: >>Dynamic scoping is not a particularly good candidate for inclusion in >>a language because the programmer can implement it by hand (at least in >>C++ and Ada) and with good program design it should be rarely used. But it is *always* used (in C++ and Ada) when you raise exceptions. I admit that it is rarely needed in any other contexts. >>... The >>same goes for nonlocal gotos; these can be simulated using Ada/C++ style >>exceptions and with good program design they should be rarely used. This seems like abstraction inversion, to me. It makes more sense to me to say that exceptions are implemented in terms of non-local gotos, rather than the other way 'round. I don't understand why gotos are considered evil, whereas exceptions are OK. Raising an exception has at least as bad an effect on readability as a goto -- it's like a goto, but you can't tell (statically) where it's going to. Nonetheless, exceptions are a Good Thing (whether they are done like Ada or like Piercarlo Grandi wants). >Without wanting to argue either for or against dynamic scoping (some of >my favourite languages have it and some haven't), the claim that "the >programmer can implement it by hand" is true only in the sense that the >programmer can implement most control structures using "if ... goto". >You can in this sense implement almost _anything_ by hand, but you'd be >mad to, and you wouldn't put up with a language designer using that >excuse to omit while loops from the language. Well, in Smalltalk, while loops are not exactly part of the core language -- they're part of the predefined library. And I think that's a pretty elegant way to do it. >In fact, the programmer can _not_ implement dynamic scoping easily by >hand in Ada and thanks to the arcane scope rules of C++ (from time to >time I reread the draft C++ standard trying to find out what the scope >rules _are_, does _anyone_ know?) it is even less true there. > >There are a number of points about dynamic scoping: >(a) it dilutes the "ownership" of a name. > For this reason I don't think it would be appropriate for Ada. >(b) dynamically scoped variables are automatically unwound whenever > a contour rebinding them is exited for whatever reason. >(c) binding and unbinding dynamically scoped variables is expected > to be CHEAP. >Simulating dynamically scoped variables in Ada or C++ would seem to require >- introducing a *visible* shadow variable to hold the outer value >- setting up an exception handler to unwind and resignal >- remembering to unwind at _every_ return point. >This is a heavy burden on the programmer, worse in my view than having >to use "if ... goto .." instead of "while". It is also likely to be >seriously less efficient than a reasonable mechanism implemented by the >compiler. The above can simulated in Ada using controlled types. It's possible to implement controlled types efficiently, but it's not easy in the general case, and I don't know of any Ada compilers that do so. - Bob