FACTOID # 136: Nauru, Tokelau and Western Sahara are the only three countries without official capital cities.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Spaghetti code
A plate of spaghetti looks twisted and tangled, which is where the name for spaghetti code comes from.
A plate of spaghetti looks twisted and tangled, which is where the name for spaghetti code comes from.

Spaghetti code is a pejorative term for source code which has a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs. It is named such because program flow tends to look like a bowl of spaghetti, i.e. twisted and tangled. Structured programming greatly decreased the incidence of spaghetti code, and is widely regarded as one of the most important advances in programming history. This is a file from the Wikimedia Commons, a repository of free content hosted by the Wikimedia Foundation. ... This is a file from the Wikimedia Commons, a repository of free content hosted by the Wikimedia Foundation. ... For other uses, see Spaghetti (disambiguation). ... It has been suggested that this article or section be merged with pejoration. ... Source code (commonly just source or code) is any series of statements written in some human-readable computer programming language. ... In computer science and in computer programming, statements in pseudocode or in a program are normally obeyed one after the other in the order in which they are written (sequential flow of control). ... GOTO is a statement found in many computer programming languages. ... Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. ...


The term is also used as in a pejorative sense to imply that a given work is difficult for the user of the term to follow. There are no known objective consensus metrics to measure "Spaghetti-ness". What may be easy for one person to follow may not be easy for another.

Contents

Examples

Below is an example of what would be considered a trivial example of spaghetti code in BASIC. The program prints the numbers 1 to 10 to the screen along with their square. Notice that indentation is not needed and that the program's goto statements create a reliance on line numbers. Also observe the unpredictable way the flow of execution jumps from one area to another. Real-world occurrences of spaghetti code are more complex and can add greatly to a program's maintenance costs. BASIC (Beginners All-purpose Symbolic Instruction Code) is a family of high-level programming languages. ...

 10 i = 0 20 i = i + 1 30 print i; " squared = "; i * i 40 if i < 10 then goto 20 50 print "Program Completed." 60 end 

Here is the same code written in a structured programming style: Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. ...

 for i = 1 to 10 print i; " squared = "; i * i next i print "Program Completed." end 

The program jumps from one area to another but this jumping is predictable and formal. This is because using for loops and functions are standard ways of providing flow control whereas the goto statement encourages arbitrary flow control. Though this example is small, real world programs are composed of many lines of code and are difficult to maintain when written in a spaghetti code fashion. It has been suggested that Foreach be merged into this article or section. ... In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code. ... In computer science control flow (or alternatively, flow of control) refers to the order in which the individual statements, instructions or function calls of an imperative or functional program are executed or evaluated. ...


Assembly and script languages

When using the many forms of assembly language (and also the underlying machine code) the danger of writing spaghetti code is especially great. This is because they are low level programming languages where equivalents for structured control flow statements such as for loops and while loops seldom exist. Many scripting languages have the same deficiencies: this applies to the batch scripting language of DOS and DCL on VMS. See the terminology section, below, regarding inconsistent use of the terms assembly and assembler. ... Machine code or machine language is a system of instructions and data directly understandable by a computers central processing unit. ... This article does not cite any references or sources. ... It has been suggested that Foreach be merged into this article or section. ... In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. ... Instructions on how to use the directory command. ... DCL is the standard Command line interface (CLI) adopted by most of the operating systems that were sold by the former Digital Equipment Corporation (which has since been acquired by Hewlett-Packard). ... OpenVMS[1] (Open Virtual Memory System or just VMS) is the name of a high-end computer server operating system that runs on the VAX[2] and Alpha[3] family of computers developed by Digital Equipment Corporation of Maynard, Massachusetts (DIGITAL was then purchased by Compaq, and is now owned...


Nonetheless, adopting the same discipline as in structured programming can greatly improve the readability and maintainability of such code. This may take the form of conventions limiting the use of goto to correspond to the standard structures, or use of a set of assembler macros for if and loop constructs. Most assembly languages also provide a function stack, and function call mechanisms which can be used to gain the advantages of procedural programming. Macros can again be used to support a standardized form of parameter passing, to avoid the accumulate and fire anti-pattern. Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. ... In computer science, a function stack (or call stack) is a special stack which stores information about the functions/subroutines in a computer program which are currently being executed. ... In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code. ... This does not adequately cite its references or sources. ... Accumulate and fire is a programming style in which the program sets a number of global variables or objects, then invokes subprograms or methods which operate on the globally set values. ...


Programs written in higher-level languages with high-level constructs such as for loops (as in the second example above) are often compiled into assembly or machine code. When this process occurs, the high-level constructs are translated into low-level "spaghetti code" which may resemble the first example above in terms of control flow. But because compilers must be faithful to high-level constructs in the source code, the problems that plague languages like BASIC do not haunt higher-level languages. It does, however, mean that debugging even mildly optimized code with a source-level debugger can be surprisingly confusing. A high-level programming language is a programming language that, in comparison to low-level programming languages, may be more abstract, easier to use, or more portable across platforms. ...


See also

Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. ... The International Obfuscated C Code Contest (abbr. ... Ravioli code is a type of program structure, characterized by a number of small and (ideally) loosely-coupled software components. ... Lasagna in the crinkly American style Lasagna code is a type of program structure, characterized by several well-defined and separable layers, where each layer of code accesses services in the layers below through well-defined interfaces. ...

References

This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL. This article does not cite any references or sources. ... “GFDL” redirects here. ...

External Links


  Results from FactBites:
 
Spaghetti code - Wikipedia, the free encyclopedia (657 words)
Spaghetti code is a pejorative term for source code which has a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs.
Spaghetti code is an example of an anti-pattern.
When using the many forms of assembly language (and also the underlying machine code) the danger of writing spaghetti code is especially great.
spaghetti: Definition and Much More from Answers.com (721 words)
Spaghetti is the plural form of the Italian word spaghetto, which is a diminutive of "spago," meaning "thin string" or "twine".
Spaghetti is cooked by boiling the pasta in salted water until soft.
An emblem of Italian cuisine, spaghetti is frequently served in tomato sauce, which may contain various herbs (especially oregano and basil), olive oil, meat, or vegetables.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.