[comp.misc] Nasty Gotos and Poor Coding Practice...

trb@stag.UUCP ( Todd Burkey ) (05/09/89)

In article <...> someone writes:
>	printf ("Enter your sex: ");
>	while (sex != "m" && sex != "f") {
>		gets (sex);
>		if  (sex != "m" && sex != "f")
>			printf ("<m> or <f> only: ");
>	}

Actually, I am surprised nobody mentioned the poor logic in 1) assuming
that sex didn't already start with 'm' or 'f', and 2) that you should
never make the user enter an 'm' when they mistakenly type an 'M' in
response to a unoptioned prompt. Very, very user unfriendly.
Personally, I prefer to use a single routine to do all my prompting
and verification of input for me. I have a set or routines that allow
me to simply do the following for the above:

  sprompt(NEW,sex,"Enter your sex [m:1,m|f]:","<m> or <f> only:");

and my library routine takes care of the length of input checking,
error analysis, secondary prompting (a "?" response to input will
give the second string of text as extra help), and default input
(what you get when you enter a C/R...in this case an 'm'). I use
the same single line prompting for multi-variable prompting and
updating as well (simplifies writing small database programs and
changing your code to support graphic systems at a later date).

For the record, I have no problem using a goto when I decide I need to
loop back in my code for some reason. Why waste the time of rethinking
your logic and possibly introducing a bug in existing code by changing
it? I agree that a poor programmer can easily make unmaintainable code
by an over-abuse of gotos, but a poor programmer has MANY other ways
to generate poor code, so what's one more.

  -Todd Burkey
   trb@stag.UUCP