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.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!seas.gwu.edu!mfeldman From: mfeldman@seas.gwu.edu (Mike Feldman) Newsgroups: comp.lang.ada Subject: Re: On quitting an iterator prematurely Message-ID: <1782@sparko.gwu.edu> Date: 13 Apr 90 22:50:43 GMT References: <9004041704.AA17624@ajpo.sei.cmu.edu> <1151@enea.se> <120.26224a7e@wsuiar.uucp> <6827@crdgw1.crd.ge.com> Reply-To: mfeldman@seas.gwu.edu () Organization: The George Washington University, Washington D.C. List-Id: In article <6827@crdgw1.crd.ge.com> kassover@jupiter.crd.ge.com (David Kassover) writes: > >This question of "misuse" of Ada exceptions begins to remind me >of the jihad between the structured programming mullahs who >maintain that loops must be exited only in one place, and the >rest of us in the real world, who know better. > Whoa. First, let's not get back into using inflammatory language. I think there are _lots_ of equally valid points of view on exceptions. The group has calmed down and gotten back to technical stuff; I, for one, would appreciate our all restraining ourselves from words like "jihad" and "mullah." Now to the issue: there is a perfectly legitimate school of thought that holds that one important purpose of the exception-raising/handling structures in Ada is to improve readability, specifically by creating a clear visual distinction between "normal" processing and "abnormal" (unusual, unexpected, let's not play semantics games here) processing. Assume you belong to this school (I do, or I wouldn't bore you with this). You then face the question of drawing the line, if you can, separating the normal from the abnormal. Here is where science stops and art begins, and the line is not bright and crisp. So there is plenty of room to discuss, like polite adults, this essentially philosophical question. At the two extremes are the case of popping an empty stack (clearly, at least to me, an abnormal situation calling for an exception report) and the case of handling CONSTRAINT_ERROR when, given a DAYS_OF_WEEK enumeration, (MON, TUE, WED, THU, FRI, SAT, SUN), one finds tomorrow by taking the 'SUCC of today. If today is SUN, this will obviously raise CONSTRAINT_ERROR. Clearly, to me, handling CONSTRAINT_ERROR here is _not_ the thing to do, because MON indeed follows SUN once a week. The only thing that makes it "abnormal" is a language idiosyncracy under which wraparound enumerations aren't supported directly. While handling CONSTRAINT_ERROR here is obviously permitted, I hold that doing so dilutes the readability benefits provided by exceptions. Better to face the language idiosyncracy directly, writing if today = SUN then tomorrow := MON else tomorrow := DAY'SUCC(today); end if; I have heard it conjectured that the "extra" test in the IF statement will lead to that ol' bugaboo, inefficiency; I haven't yet seen it proved, therefore will assume negligible performance differences that can easily be traded away for increased human performance. (Let me know if you have good evidence to the contrary). OK, so much for my two extreme cases. I happen to think that Kassover's example is an easily justified intermediate case. Should we start a discussion thread about other such intermediate cases? I'd find it worthwhile unless and until it degenerates to name-calling. By the way - I don't know of any structured-programming "mullahs" these days. Use of new features always moves from the extremes to the middle, as our understanding of them matures. If a project wants to set a local coding standard - again for whatever readability improvement they think they are after - that says "one exit from a loop, one return from a subprogram", I think that is their privilege, and we don't have to flame them for it. I wouldn't set such a standard myself, but I think they have a valid viewpoint. I have seen such standards. In industry. Is this Kassover's "real world"? I have _lots_ of friends in the academic world; I don't think any of 'em are "mullahs." --------------------------------------------------------------------------- Prof. Michael Feldman Department of Electrical Engineering and Computer Science The George Washington University Washington, DC 20052 +1-202-994-5253 mfeldman@seas.gwu.edu ---------------------------------------------------------------------------