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-Thread: a07f3367d7,dbbbb21ed7f581b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!feeder.erje.net!news.osn.de!diablo1.news.osn.de!noris.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Operation can be dispatching in only one type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <025105f2-5571-400e-a66f-ef1c3dc9ef32@g27g2000yqn.googlegroups.com> <94e76749-c49c-45aa-b7dc-386da0d71c66@e4g2000prn.googlegroups.com> <1u0im1tdws15u.1n9v9rz7bu4t4$.dlg@40tude.net> <39kf90ha60px$.d7746cf5cx6h.dlg@40tude.net> <691d6892-bc5e-4d81-8025-c36556bf2593@13g2000prl.googlegroups.com> <1h9hilcg5i6il.12edpgu4szw1h.dlg@40tude.net> <1wtsriaxu0s4s$.ikwnnz5teukp$.dlg@40tude.net> <1iipp3bn16fe2.yqa1gz1ru17a$.dlg@40tude.net> <18wh86jvjvoe0.cofxcc8udm6q$.dlg@40tude.net> Date: Sat, 21 Nov 2009 14:07:09 +0100 Message-ID: <1g7zvfog4ey46$.17p5m90nego3.dlg@40tude.net> NNTP-Posting-Date: 21 Nov 2009 14:07:10 CET NNTP-Posting-Host: 22b28c3b.newsspool2.arcor-online.net X-Trace: DXC==JaWHn;P^3VV;Ef1`Jk54\A9EHlD;3YcR4Fo<]lROoRQ8kFR;SN[P X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8185 Date: 2009-11-21T14:07:10+01:00 List-Id: On Sat, 21 Nov 2009 00:02:59 -0600, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:18wh86jvjvoe0.cofxcc8udm6q$.dlg@40tude.net... >> On Thu, 19 Nov 2009 17:54:40 -0600, Randy Brukardt wrote: >>> "Dmitry A. Kazakov" wrote in message >>> news:1iipp3bn16fe2.yqa1gz1ru17a$.dlg@40tude.net... > ... >>> That might be true in general, but definitely not in this case: a handler >>> for Program_Error is *always* wrong (unless it is a global handler for *any* >>> exception), as Program_Error always represents a program bug. So I don't >>> see how "existing" handlers can be confused. >> >> exception >> when Error : others => >> some cleanup -- This usually becomes a problem >> raise; > > If that's the case, "some cleanup" is seriously flawed. An "others" handler > has to always work no matter what condition come into it, and in particular > cannot depend on the code/data it surrounds to be in any particular state. > The clean up code needs to be aware that data structures may be corrupt; if > it isn't it of course will cascade errors and generally make a mess -- but > in that case it is just junk code doing more harm than good. Right, "others" stands for all "legal" exceptions propagating out of the body, which the programmer was unable to specify, because it is too much work to do. The problem is that "illegal" exceptions indicating broken program do not belong here, and because of the lack of contracts you cannot separate them. The pattern is wrong, but there is no other. > I believe this particular pattern ("others" handler containing explicit > cleanup) usually represents a bad design. Clients (or even the implementers > of ADTs) often forget to include the cleanup where it is needed. These days, > I try to put all needed cleanup into the ADTs, so that they get cleaned up > no matter what -- finalization is pretty much the only certainty in Ada. And > in that case, you don't need these kind of exception handlers. I agree, but that only moves cleanup from one place to another (Finalize). There is no way to get rid of it. Within Finalize cleanup has even more chances to get perplexed, because in Ada you cannot know whether Finalize was called upon normal leaving the scope due to an exception propagation. Further the Ada's construction model is not enough fine to fully accommodate this pattern. For accessibility checks it could also aggravate the problem because accessibility is not invariant to moving from one body to another. The same code might be OK or not OK within different bodies. > And the huge log of messages doesn't matter, you only need the first one > (presuming every "others" handler logs the data). No it will be the last one (it is a stack of errors which gets unwound), but most likely it will be consumed by something else, like Program_Error. That is a reason for the "wrong" pattern with "others". Yes it is bad, but it lets you to log Exception_Information *before* things explode. >> But of course the proper solution would be contracted exceptions. > > I don't see how that would help. The problem is used "others" when you > really need to list the exceptions that you are expecting. If the compiler > is smart enough to be able to prove that no bounded errors occur (and no > constraint violations either), maybe that would do some good, but I doubt > that you will see such compilers anytime soon. In the absence of that, you > have to put Program_Error, Constraint_Error, and Storage_Error into every > contract, so you don't gain much. It should be more intelligent than Java. For example, "I don't do Storage_Error if there is N (static value) free bytes of stack", "I don't raise Program_Error from Initialize/Finalize" etc. An important issue to me is exception contract bound to some precondition, which ensures absence of specified exceptions. When an exception happens, it is not range error, or accessibility check to blame, but the precondition violated. >>>> The difference is that for string bound there is a way to do it safe and >>>> for 'Access there is none (and I also agree with Robert's response.) >>> >>> Well, Ada 2012 (or whatever it will be called) should help that out by >>> giving you a way to compare accessibilites (via memberships). So at least >>> you will be able to make checks to avoid the problem. Better than nothing, >>> but still not ideal. The better way to avoid the problem is to never, ever >>> use anonymous access types. (Named access types have checks that are always >>> made at compile-time for most compilers -- but not Janus/Ada, because of >>> generic sharing.) >> >> The problem is not bound to only anonymous types. It also appears when you >> convert access types. The source type (or both) might be a formal generic >> parameter, so you cannot statically ensure that a "local" pointer is >> converted no a "less local" one. Pool specific pointers need to be >> converted though one target object is derived from another. Here everything >> is broken: generic contract, meaningless conversion, meaningless check, >> meaningless exception. > > In this case, whether a check will fail is known statically for any compiler > that generates generics via macro substitution (that is all Ada compilers > other than Janus/Ada). I can hardly imagine that there exists a compiler > that will generate "raise Program_Error" unconditionally without generating > a warning! Yes it generates that warning, and the warning is ignored. Any warning is ignored, that is one the most fundamental principle of modern software design. (:-)) The code was modified to X.all'Unchecked_Access. Everybody is happy? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de