Spaghetti programming

In the early days of computers, many programs were small and simple, so programmers could often start writing their programs without any planning whatsoever. They’d write part of a program, test it, and add more instructions over and over again until the program finally worked (if it ever did).

Unfortunately, this haphazard approach to programming often lead to something called spaghetti programming, which gets its name from the idea of untangling strands of spaghetti.

In a well-organized program, you can easily see where a program starts, where it ends, and how it proceeds step by step. In a spaghetti program, the programmer just starts typing commands without any thought of organization whatsoever, which can be like dumping your laundry on the floor and then wondering why you can never find a matching pair of socks in a hurry.

In a small program, dumping commands haphazardly may be troublesome but still manageable. In a large program, such haphazard spaghetti programming can make a program completely incomprehensible so no one (including the original programmer) can figure out how it works ever again (if it ever works).

The code used in the program is the following:


GOTO [LabelOne]
[LabelFour]
 PROMPT “How much money do you have”; MyCash
 GOTO [LabelThree]
[LabelTwo]
 END
[LabelOne]
GOTO [LabelFour]
[LabelThree]
 PRINT “You owe me = “; MyCash * .95
 GOTO [LabelTwo]

Believe it or not, this program actually works, but trying to follow the logic is nearly impossible. Reorganizing the program can create the much simpler equivalent program:


PROMPT “How much money do you have:”; MyCash
PRINT “You owe me =”; MyCash * .95
END

Which version of the program do you think is easier to read, understand, and modify?


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply



eXTReMe Tracker