Re: Comparing string input to enum data type



"dtschoepe@xxxxxxxxx" <dtschoepe@xxxxxxxxx> writes:
On Feb 28, 10:21 am, rober...@xxxxxxxxxxxxxxxxxx (Walter Roberson)
wrote:
#define COLORS red, blue, green, yellow, black, purple, pink

It isn't clear why you chose to #define those. Any change in them
needs to be reflected in the routine, so decoupling the symbols from
the routine does not buy you anything obvious.
[snip]

I used #define so I would have less places to edit in case I added a
color, since I use it in at least 2 places.

You only use the COLORS macro in one place in the code you showed us,
and I can't think of a good reason to use it more than once. You do,
however, have string literals "red", "blue", etc., which would have to
be individually updated if you changed the type.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Studio 60: "The Wrap Party"--wow!
    ... unbelieveable that they wouldn't have heard of the routine. ... chose to take as them being deliberately obtuse. ... Yet they aren't Mennonites. ...
    (rec.arts.tv)
  • Re: Separating code from UI
    ... What is the preferred way for the "remote" proc to communicate back to the ... If you have a routine that may be called from ... or raising events from a class. ... When you talk about decoupling, you should be thinking 'black box' ...
    (microsoft.public.vb.general.discussion)
  • Re: F200x (was Re: When to expect a F2003 compiler?)
    ... Fortran 90 chose to ... > hobble it. ... If the called routine is declared as having CONTROLLED ... (and the declaration must match the declaration in ...
    (comp.lang.fortran)
  • Re: Juggling Podcast 18 - Thomas Dietz interview, WJF review and more sports cha
    ... jugglingeek wrote: ... Thinking that a few tricks strung together the ... night before to a piece of music that he chose the night before along with ... some pooly thought out and badly rehursed comedy would be a good routine. ...
    (rec.juggling)