From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c++
Subject: Re: Re: GOTO, was: Tiny proposal for named loops.
Date: 9 Oct 92 00:48:03 GMT
Article-I.D.: ulogic.404
Organization: negligable


In article <68070020@hpcupt1.cup.hp.com> jamiller@hpcupt1.cup.hp.com (Jim Miller) writes:
>
>This has (mostly) been an interesting discussion - IMHO.
>
>> Readability is subjective.  I find code without gotos more readable
>> than code with gotos.  Others, like you perhaps, find gotos to be more
>
>Readability has a LOT to do with maintainability.  If something is
>a lot more readable with a GOTO than without, I'd vote for use of a GOTO.
>
>I use GOTOs about once every 3 years.  Would not want to not have them
>in my toolbox.  However, I try and avoid them because usually they mean
>that I have not thought out the problem well in the first place.

In 10+ years of professional programming I haven't used a goto,
until today.  I have had to write some loops nested a bit deeper
than strictly required, but I preferred that to using a GOTO.

However, I'm now using C++, and attempting to read a configuration
file w/ an ifstream (the C++ forces here won't let me fall back on
good ol' fscanf()...)  Therefore I came up with this (btw: this is
from a test program, I took out the cout's the let me see what was
being read; I know that the values it reads aren't going anywhere,
that'll wait until I put this into the real program, so please no
replies saying "but you aren't storing the values anywhere!"...):


]istream &getConfigLine(istream &in)
]{
]	char szId[ID_SIZE];
]	char szLast[NAME_SIZE];
]	char szFirst[NAME_SIZE];
]	char szInitial[2];
]	int iLine;						// phone line/student "sru" number
]	int iRingSignal;				// digital input point for ring signal
]	int iSwitchHook;				// digital output point for switchhook ctl
]	int iMute;						// digital output point for mute control
]
]	//- config line:
]	//	iLine#, iRing, iSwitchHook, iMute, "id", "fname", "m", "lname"
]
]	in >> iLine;
]	skippast(in, ',');
]	if (!in || in.peek() == '\n') goto gcl_errexit;
]
]	in >> iRingSignal;
]	skippast(in, ',');
]	if (!in || in.peek() == '\n') goto gcl_errexit;
]
]	in >> iSwitchHook;
]	skippast(in, ',');
]	if (!in || in.peek() == '\n') goto gcl_errexit;
]
]	in >> iMute;
]	skippast(in, ',');
]	if (!in || in.peek() == '\n') goto gcl_errexit;
]
]
]	getqstring(in, szId, ID_SIZE);
]	skippast(in, ',');
]	if (!in || in.peek() == '\n') goto gcl_errexit;
]
]	getqstring(in, szFirst, NAME_SIZE);
]	skippast(in, ',');
]	if (!in || in.peek() == '\n') goto gcl_errexit;
]
]	getqstring(in, szInitial, 1);
]	skippast(in, ',');
]	if (!in || in.peek() == '\n') goto gcl_errexit;
]
]	getqstring(in, szLast, NAME_SIZE);
]	skippast(in, '\n');		// dump everything 'till eol
]	if (!in) goto gcl_errexit;
]
]	return in;
]
]gcl_errexit:
]	in.clear(in.rdstate() | ios::badbit);
]	return in;
]}

Oh, getqstring() reads a quoted string w/o putting the quotes
in the buffer.  skippast() eats characters until (including) the one
you specify OR a newline (the newline is left in the input stream
unless it was the character specified).  I know that there is an 
istream::ignore() but it requires a character to read till AND a 
numeric limit and I make no assumptions about the line length (what 
good is istream::ignore() with that limitation, anyway?)

And while I'm asking, why is it you use a member function called
"clear()" to SET an error bit?!?!??!?!?!  (I got this info from
a book by Lippman)

With so many places for syntax failure, I fail to see how this
would be easier to read if I refrained from using a "goto".

btw: if anyone knows how to deal w/ reading formatted input from
a stream more easily, PLEASE let me know!

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Why do we never get an answer		|
when we're knocking at the door?	|	-Richard Hartman	
because the truth is hard to swallow 	|	hartman@uLogic.COM
that's what the war of love is for.	|
Newsgroups: comp.lang.c++