Talk:Spaghetti code

From Wikipedia, the free encyclopedia

This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.

Is what 199.29.247.140 added really spaghetti code? I'd just call it bad code, because there's no noodle like loops of goto-ing and whatnot... --Carl 13:49, 13 Oct 2004 (UTC)

I agree. It's hardly a good example of spaghetti code. I removed it. --Neg 01:21, 27 Nov 2004 (UTC)

Is there really any need for that picture of a bowl of spaghetti?

I guess looking at the spaghetti aids in understanding the chaotic nature of spaghetti code. Plus its humourous so why not. JesseHogan 07:56, 15 July 2005 (UTC)

Contents

[edit] assembly and function calls

While many assembly languages have a function stack, and apparent function calls, these are just a thin wrapper for the goto statement. They store the original location of the program counter in order to return to it later.

How is this significantly different from a function call in higher level languages? — The Storm Surfer 20:55, 18 July 2005 (UTC)
Moreover, spaghetti code is not the sine qua non of programming in assembly language, FORTRAN and early BASICs. With proper early training and mental discipline, anyone can write structured code in any computer language. My college instructor in the early 1970s referred to such programming as "good programming", long before the catch phrases "structured programming" and "object-oriented programming" came into widespread use. --QuicksilverT @ 18:10, 29 November 2005 (UTC)
The quote above is not accurate. It should mention the "gosub" statement, not a "goto". A gosub implies a return: "go to subroutine". A "goto" means you never come back.
Actually, the use of subroutine calls (such as the primitive gosub) helps eliminate spaghetti code. --Uncle Ed 01:08, 6 April 2006 (UTC)

PJTraill 15:49, 8 April 2006 (UTC) I have largely rewritten this section in accordance with the above observations.

[edit] Lo-mein code

A variation of spaghetti code with unreadable and/or outdated and misleading comments. Often includes numerous macros that call other macros that modify global variables.

PJTraill 15:59, 8 April 2006 (UTC) Has anyone got a source for this? Does anyone know people who use the term? At [1] it is unclear what it means. It was deleted from Wikipedia: see Wikipedia:Articles_for_deletion/Lo-mein_code.

[edit] NPOV: line numbering

I don't believe the 2 code fragments really illustrate spaghetti code in a fair way: it makes it seem as though the older style of BASIC, especially the line numbering, is the problem. The 2 code fragments should ostensibly be be written in the same style. I like seeing the BASIC, lord knows it facilitated more than its share of bad code, but as I no longer have access to an interpreter I don't think I can come up with a fully functional "structured" example. Ewlyahoocom 18:53, 11 February 2006 (UTC)

[edit] Another example

Just try to figure out how this baby gets the sorting done (it looks like shell sort). It's converted from BASIC to QBASIC. I think it as from a library book I once read when I was little. --Zom-B 00:12, 05 November 2006 (UTC)

SCREEN 0
 INPUT "How many numbers to sort? "; T
 DIM n(T)
 FOR i = 1 TO T
   PRINT "NUMBER:"; i
   INPUT n(i)
 NEXT i
 'Calculations:
 C = T
E180:
 C = INT(C / 2)
 IF C = 0 THEN GOTO C330
 D = T - C
 E = 1
I220:
 f = E
F230:
 g = f + C
 SWAP n(f), n(g)
 f = f - C
 IF f > 0 THEN GOTO F230
 E = E + 1
 IF E > D THEN GOTO E180
GOTO I220

C330:
 PRINT "The sorted list is"
 FOR i = 1 TO T
   PRINT n(i)
 NEXT i

[edit] Spaghetti code vs monolithic code

I'm looking for the proper terminology that describes code that isn't a jumbled mess per se, but is hard to decouple or modularize. Perhaps this goes hand-in-hand with spaghetti code, but for example monolithic kernel doesn't seem to imply sloppy coding practice. Can the article be made to clarify if and how these things are different? Ham Pastrami (talk) 12:18, 3 April 2008 (UTC)