From: "Theodore E. Dennison" <dennison@escmail.orl.mmc.com>
Subject: Re: Ada 83 Style Query
Date: 1996/05/06
Date: 1996-05-06T00:00:00+00:00 [thread overview]
Message-ID: <318E6AA4.4487EB71@escmail.orl.mmc.com> (raw)
In-Reply-To: 9605061517.AA05599@most
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 |
next prev parent reply other threads:[~1996-05-06 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-05-06 0:00 Ada 83 Style Query W. Wesley Groleau (Wes)
1996-05-06 0:00 ` Theodore E. Dennison [this message]
1996-05-06 0:00 ` John Herro
1996-05-07 0:00 ` Laurent Guerby
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox