From: magnus@thep.lu.se (Magnus Olsson)
Subject: Spaghetti (was Re: Branching in HLL vs. Assembler (was Re: The need for an assembler))
Organization: Theoretical Physics, Lund University, Sweden
Date: Thu, 3 Sep 1992 10:06:24 GMT

In article <1992Sep3.043632.29125@news.columbia.edu> lasner@watsun.cc.columbia.edu (Charles Lasner) writes:
>In article <1992Sep1.083701.2898@pollux.lu.se> magnus@thep.lu.se (Magnus Olsson) writes:
>>In article <1992Aug31.160756.23324@news.columbia.edu> lasner@watsun.cc.columbia.edu (Charles Lasner) writes:
>>>In article <1992Aug28.221421.18061@ttinews.tti.com> hollombe@polymath.tti.com (The Polymath) writes:
>>>>
>>>>The problem isn't so much with the GOTO as with the lack of a COMEFROM.
>>>>
>>>>Suppose you're neck deep in the bowels of a multi-megabyte system and you
>>>>come across a label in the source code.  There could be any number of
>>>>GOTOs in the code that branch to that label.  Even if the original
>>>>programmer was kind enough to provide a comment listing them all (I've
>>>>only seen that once and I wrote it), figuring out which particular one
>>>>you're concerned about can be a nightmare. (In a language like BASIC the
>>>>problem is even worse since _every line_ can be the target of an arbitrary
>>>>number of GOTOs).
>>>
>>>a)	That's ludicrous since no code does a GOTO the middle of a module
>>>therefore the largest thing to worry about is the size of the module you
>>>are working on where the label exists.
>>
>>With all respect for your great experience, have you ever programmed
>>in BASIC? 

[...]

>Yes, spaghetti code can happen in any language, probably even PASCAL if you
>work at it :-).
>
>BTW, I have 15,000 line assembler "modules" as well; they ain't spaghetti code.

Of course; the fact that a language _allows_ you to write spaghetti
certainly doesn't imply that you _should_ do so. But if you give
people guns, somebody is sooner or later bound to shoot himself in the
foot. The "bondage and discipline" school of programming (Wirth et al)
advocate that a language shouldn't _allow_ people to shoot themselves
in the foot. I don't think I can agree wholeheartedly with that. 

However, I think the Polymath was concerned about the problem of
understanding and analyzing other people's code (maybe written by real
goofs).

>>
>>For example, it was common practice among certain programmers to write
>>"clever" code like this (and this is just a simplified example, actual
>>code would probably look much worse):

[...]

>>(Note especially that the NEXT statement in line 1510 refers to
>>different control variables depending on from where the loop was
>>entered). 
>
>Cute, but that's "playing" with a language instead of using it.  

The point is that lots of people actually wrote (write?) code like
that, and thought themselves smart for doing it. 

I'm not trying to say that you shouldn't use gotos if you know what
you're doing, just that a language allowing bad uses of goto will lead
to people writing bad programs. (Unfortunately, as somebody remarked
earlier, it is possible to write bad code in *any* language, so
abolishing goto doesn't help).

>Couldn't
>you use statements like NEXT I to enforce some structure? 

Yes.

>>Horrible? Yes, of course, but the alternative (manually renumbering
>>maybe hundreds of lines) would be even worse.
>
>Yes, a BASIC analogy to my tale of the punched card people.
>
>However, even 4K PDP-8 POLY BASIC can renumber its statements, and that goes
>back to 1969, so this must be some really crummy BASIC.  (Anything to do
>with Microsoft? :-))

No, actaully not (all Microsoft Basics I've had the dubious pleasure
of using did have a RENUM command). But most of the cheapo home
computers marketed in the early 1980's had really small BASICs, and
often pretty bad ones as well.

Magnus Olsson                   | \e+      /_
Dept. of Theoretical Physics    |  \  Z   / q
University of Lund, Sweden      |   >----<           
Internet: magnus@thep.lu.se     |  /      \===== g
Bitnet: THEPMO@SELDC52          | /e-      \q
Newsgroups: alt.folklore.computers