Cartoon by XKCD http://xkcd.com/844/
The writing of programming code is like many other technical challenges, there are good and bad ways to do it, sort of like cooking. We have all done it but some folks can do it really well. For the rest of us, we only do it well enough to stay alive.
In the code business, one occasionally comes across statements like the cartoon above that refer to “spaghetti code”. Basically this is what can happen to you if you are sloppy with your technique or have a piece of code that has been edited and modified to pieces. An example of spaghetti code is given below (in Basic)*:
10 i = 0
20 i = i + 1
30 PRINT i; ” squared = “; i * i
40 IF i >= 10 THEN GOTO 60
50 GOTO 20
60 PRINT “Program Completed.”
Even in this simple piece of code you see a lot of jumping around and references to line numbers. Such code is likely to be unstable and is not elegant. A better, more structured programming way to do the same thing is given below:
FOR i = 1 TO 10
PRINT i; ” squared = “; i * i
PRINT “Program Completed.”
A large piece of code written in the first style would be an organizational mess with it quite difficult for someone else who did not write it to follow while the second piece of code is clean and it is easy to figure out what is going on.