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,FREEMAIL_FROM, 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: johnherro@aol.com (John Herro) Subject: Re: Ada 83 Style Query Date: 1996/05/06 Message-ID: <4mlrsm$2m6@newsbf02.news.aol.com>#1/1 X-Deja-AN: 153361777 sender: root@newsbf02.news.aol.com references: <9605061517.AA05599@most> organization: America Online, Inc. (1-800-827-6364) newsgroups: comp.lang.ada Date: 1996-05-06T00:00:00+00:00 List-Id: "W. Wesley Groleau (Wes)" writes: > 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. One thing to consider is that none of the commands can match Ada reserved words, such as BEGIN, REVERSE, ACCEPT, RECORD, END, USE, etc. If you write the program with an enumeration type, and later someone wants to add an END command, you'll have to redesign the program! However, if none of the commands match reserved words and you're sure you won't later be adding such commands, then using an enumeration type is certainly a viable way of doing it. > The sore spot is the need for an exception handler ... If you do choose to use an enumeration type, adding an exception handler for the case of an incorrect incoming string should be simple. I suggest localizing the scope of the exception handler as much as possible with a block, like this: type Command_Type is (Go, Stop, ..., Unrecognized); Command : Command_Type; Input : String(1 .. 80); Input_Len : Integer; ... Get_Line(Input, Input_Len); begin Command := Command_Type'Value(Input(1 .. Input_Len)); exception when Constraint_Error => Command := Unrecognized; end; case Command is ... - John Herro Software Innovations Technology http://members.aol.com/AdaTutor ftp://members.aol.com/AdaTutor