[net.lang] Teaching students with GOTO

steven@mcvax.UUCP (Steven Pemberton) (05/13/84)

>But I pity his students: his sample [Fortran] programs
>were about 1/5 to 1/4 "goto"s.

I knew a lecturer who used to teach Algol 60 in the same way:
for the then part of an if statement he would only use a goto.
When his department decided to move to Pascal, he even did the same there!
He would teach his students first to declare a healthy supply of labels,
and then program the algorithm. He was very upset the day he discovered
that the compiler generated a jump over the then part (thus a jump over a jump)
rather than negating the test and directly jumping to the destination.

darryl@ism780.UUCP (05/16/84)

#R:mcvax:-580600:ism780:14700001:000:389
ism780!darryl    May 15 06:22:00 1984

We used to see this quite a bit at the UCLA computer club.  The intro
to programming class used PL/I (I think they've moved to Pascal now)
and it was taught by any graduate student that claimed to have programmed
a computer.  We would often see programs that lined up in column 7,
each if/then having a goto, and labels like "L900:".  SIGH.

	Darryl Richman      ...!cca!ima!ism780!darryl

kar@ritcv.UUCP (Kenneth A. Reek) (05/17/84)

<>

	The last time I taught our introductory programming course (Pascal),
I had one student who wrote BASIC programs in Pascal.  Goto's and labels,
one letter or letter-digit variable names, no loops except "for", "if"
statements with only a "then" clause which contained only one statement,
and so on.  It was awful.

	Ken Reek, Rochester Institute of Technology
	{allegra,seismo}!rochester!ritcv!kar

dont@tekig1.UUCP (Don Taylor) (05/18/84)

X
     When I was struggling on my own, trying to teach myself programming, I
was looked on favorably by the director of the department of the local
community college, where I could bum machine time after hours.  One evening
he explained how I could name my variables X1000, X1001, X1002, when I got
to a point where I couldn't think of a good name for something, or didn't
want to worry about it!  I think this was to answer my question about why
a particular style of naming might be chosen.
     Not to fear, I repented from this path of darkness, and journeyed to
study under the true practitioners of the craft.
Don Taylor

steiny@scc.UUCP (Don Steiny) (05/18/84)

***

	When I took my first programming class Bill McKeeman (sp?) 
had a simple rule for the use of goto's in Alogol W -
"...if anyone uses one they will fail the course."

			Don Steiny
			Personetics

liberte@uiucdcs.UUCP (05/20/84)

#R:mcvax:-580600:uiucdcs:26400011:000:1664
uiucdcs!liberte    May 20 03:58:00 1984

Objection, your Honor.

/**** uiucdcs:net.lang / steiny@scc /  6:21 pm  May 19, 1984 ****/
	When I took my first programming class Bill McKeeman (sp?) 
had a simple rule for the use of goto's in Alogol W -
"...if anyone uses one they will fail the course."
/* ---------- */

Now I am not a liberal user of goto's, but I do object to impossing this kind
of rule unless there is a corresponding rule that the instructor will never
give any assignments in which goto's may be used appropriately.

What is "appropriate" use of a goto?  There seem to be two cases.

	1. Exiting from deep within a program on some error condition.
	   The original Pascal compiler has such a goto on premature EOF and
	   if such an exit is not provided in the language.

	2. Exiting from multi-condition (and multi-nested) loops
	   where the conditions may not all be evaluated and
	   if such an exit is not provided in the language.

Avoiding use of goto's in these cases requires the addition of often
obscure boolean variables, assignments and testings all the way out to
the exit point.  For case 2, duplication of code may do the same.
Sometimes greater clarity can be achieved, but not usually.

In such cases, I have no qualms about using goto's.  I can appreciate
the problems of overuse of goto's having rewritten other peoples
spaggetti (sp) code.  But I have seen many students (including myself) 
struggling to figure out how to arrange a loop to exit properly
when a goto (or exit) would have made things a lot simpler.

Daniel LaLiberte          (ihnp4!uiucdcs!liberte)
U of Illinois, Urbana-Champaign, Computer Science
{moderation in all things - including moderation}

jab@uokvax.UUCP (05/29/84)

#R:mcvax:-580600:uokvax:9000024:000:1103
uokvax!jab    May 29 00:28:00 1984

One person just submitted a response to an article to the effect of
"goto's (he was using Algol W as the example) have a place: to exit a program
on an error, and to break out of loops".

You're right, I agree. Algol W isn't the best example, however:
	i) There is an "assert (expr)" statement that halts the program whenever
	   "expr" is not true.
	ii) In Algol W, there is no loop-exiting construct, which is a real
	   pain. Any reasonable language should provide you with one; the
	   constructs in C are in the right direction, although I'd like to
	   be able to specify "break out of the loop I'm in, hopping out of
	   the scope of this loop and the next deeper one" --- operationally
	   a "break 2;" construct.

Such control structures should be provided as part of the language.

Were I teaching a programming class, I would insist on justification of why
people used "goto" statements; if it's not one of the above reasons, I'd view
it as a bad practice and grade off. (Possibly I'd grade off anyway, if they
could have recoded to get around it with little pain.)

	Jeff Bowles
	Lisle, Il

emjej@uokvax.UUCP (05/29/84)

#R:mcvax:-580600:uokvax:9000025:000:534
uokvax!emjej    May 29 09:30:00 1984

/***** uokvax:net.lang / jab / 12:28 am  May 29, 1984 */
	ii) In Algol W, there is no loop-exiting construct, which is a real
	   pain. 
/* ---------- */

I fear that the Algol W construct

	<T expression>	::=	<blockhead> (<statement> ;)* <T expression> end

or something to that effect has been forgotten about. You can thus write
your loop with exit as

	while begin
		stuff;
		predicate
	end
	do
		more stuff;

if you want to. Just another case of providing power through generality
rather than special cases...

						James Jones

kar@ritcv.UUCP (05/29/84)

> Now I am not a liberal user of goto's, but I do object to impossing this kind
> of rule unless there is a corresponding rule that the instructor will never
> give any assignments in which goto's may be used appropriately.
> Daniel LaLiberte (ihnp4!uiucdcs!liberte) 

Remember, this was an introductory programming course.  Sure there are places
where using goto's make more sense than not using them, but this doesn't happen
often enough in introductory projects to worry about.  Certainly not often
enough to risk the bad habits and sloppy thinking that can result from allowing
goto's.  When you are little, you get lots of similar rules (Don't go in the
street) that are later modified when you are better able to deal with the
subtleties involved (Look both ways before crossing the street).  I submit that
the same technique makes sense when learning programming.

	Ken Reek, Rochester Institute of Technology
	{allegra,seismo}!rochester!ritcv!kar

ron@brl-vgr.ARPA (Ron Natalie <ron>) (05/31/84)

GAK!  What makes you think that BREAK to the n-th power is better than
a goto to exit the loop.  It certainly is a lot clearer and easier to
find the label to which you are breaking, rahter than looking to see how
many loops you are in.  You just can't count indentation because BREAK
exits SWITCH, WHILE, and DO but not other blocks.  CONTINUE doesn't exit
SWITCHs.  As a stated in my previous message, just because you don't use
gotos don't think that you are writing structured code.  You can do some
pretty gross unstructured things even without gotos.

-Ron

steiny@scc.UUCP (Don Steiny) (05/31/84)

***
>> Now I am not a liberal user of goto's, but I do object to impossing this kind
>> of rule unless there is a corresponding rule that the instructor will never
>> give any assignments in which goto's may be used appropriately.
>> Daniel LaLiberte (ihnp4!uiucdcs!liberte) 
> 
> When you are little, you get lots of similar rules (Don't go in the
> street) that are later modified when you are better able to deal with the
> subtleties involved (Look both ways before crossing the street).  I submit 
> that the same technique makes sense when learning programming.
> 	Ken Reek, Rochester Institute of Technology
> 	{allegra,seismo}!rochester!ritcv!kar

	I posted the original article Dan is responding to.  It said that
in my first programming course my instructor forbade goto's completely.
I agree with Ken.  I moved from Alogol to C and never used goto's for many 
years.  I was not even sure what they did.  Later I read "Software Tools" 
to learn Fortran.  Still later I learned some assembly languages and 
assembly language programming.

	I have always been biased toward believing that 
goto's provided a clumsy way of implementing conditional statements, loops 
and other such things in languages that did not have these constructs.
Today, as a professional programmer, I am glad I was given the bias
I was.   Using such a restrictive rule at first became an
organizing principle for my later learning.  


				Don Steiny
				Personetics
				109 Torrey Pine Terr.
				Santa Cruz, Calif. 95060
				(408) 425-0382

kar@ritcv.UUCP (Kenneth A. Reek) (06/03/84)

Regarding the debate on "break n" vs "goto" to get out of a loop:

My master's thesis included the design and implementation of a programming
language which I now consider to be not very noteworthy.  It did have one
interesting feature, however -- an enhanced break statement.  I originally
implemented "break n", where "n" was a constant, but quickly realized that
something better was needed.  I allowed loops to be labelled and put in
"break x", where "x" was a loop label, thus avoiding the problem of counting
levels of indenting and program maintenence.

This allowed one to easily and safely break out of (or continue) nested loops
other than the innermost one enclosing the statement.  There was no need for
a goto statement in the language.

mwm@ea.UUCP (06/06/84)

#R:mcvax:-580600:ea:5400006:000:1057
ea!mwm    Jun  6 12:43:00 1984

/***** ea:net.lang / brl-vgr!ron / 10:26 pm  May 31, 1984 */
GAK!  What makes you think that BREAK to the n-th power is better than
a goto to exit the loop.  It certainly is a lot clearer and easier to
find the label to which you are breaking, rahter than looking to see how
many loops you are in.  You just can't count indentation because BREAK
exits SWITCH, WHILE, and DO but not other blocks.  CONTINUE doesn't exit
SWITCHs.  As a stated in my previous message, just because you don't use
gotos don't think that you are writing structured code.  You can do some
pretty gross unstructured things even without gotos.

-Ron
/* ---------- */

Good point. While a one-level break is better than a goto, it isn't clear
that "break 23" is better than a goto. How about combining them the way
BCPL does, as:

	$(block-name
		<code>
		break block-name
		<code>
	$)block-name

In other words, label the blocks, and break <label> then leaves the labeled
block. This combines the best aspects of both, and makes it easy to find
the top of the loop, as well.

	<mike

west@sdcsla.UUCP (06/18/84)

Granted that the "GOTO" has its place in programming (bailing out of
deeply nested code when horrible things happen), I think the point of
an introductory class completely disallowing the use of "GOTO"s is
to force students to learn to program without them.

There's nothing preventing you from using them once you start programming ``on
your own'', and some people would never take the time to try avoiding "GOTO"s.

Remember these restrictions are generally made only in introductory
[e.g., freshman, sophomore] programming courses.

			-- Larry West, UC San Diego
			-- ucbvax!sdcsvax!sdcsla!west
			-- west@NPRDC