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: 103376,fb43c0ab08a05c0 X-Google-Attributes: gid103376,public From: "Theodore E. Dennison" Subject: Re: Ada 83 Style Query Date: 1996/05/06 Message-ID: <318E6AA4.4487EB71@escmail.orl.mmc.com>#1/1 X-Deja-AN: 153368596 references: <9605061517.AA05599@most> content-type: text/plain; charset=us-ascii organization: Lockheed Martin Information Systems mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3_U1 sun4m) Date: 1996-05-06T00:00:00+00:00 List-Id: W. Wesley Groleau (Wes) wrote: > > I'm working on some old code that has a long string of elsif checking > strings that come in from outside against known commands. > > Seeking opinions on the desirability of using an enumerated type with 'VAL > and a case statement. The sore spot is the need for an exception handler > when the incoming string matches none of the literals in the command list. This is one of my most common text-processing techniques. The major drawback to doing this is that the text must be a vaild Ada identifier. That means no commands called "exit" or "end" or "abort" (this comes up more often than you'd think), and nothing case-sensitive or with spaces in the middle. If you don't have control over the command names, you may be in trouble here. I don't see the exception handler being too much of a drawback. It will only be called when the command isn't in your enumeration. The only way you'd even notice the difference is if: o Invalid commands are very common AND o Your compiler has a VERY large exception overhead AND o Your enumeration is very small (only a few values with short names). In many cases, error processing throughput isn't considered that vital. In most other cases, the time taken to discover that the string isn't a command will dwarf the time taken in "exception overhead". If these commands are comming from a human user, the time taken waiting for him/her to respond will dwarf both. So why not code it in the easiest, most maintainable way? I don't see any reason other than speed for an exception handler to be a "sore-spot". It should be way easier to read, understand, and maintain than a huge "if..elseif..." statement. Plus you can do nifty stuff like loop through the list of commands. -- T.E.D. | Work - mailto:dennison@escmail.orl.mmc.com | | Home - mailto:dennison@iag.net | | URL - http://www.iag.net/~dennison |