Jump to content

Unstructured programming

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jesjimenez (talk | contribs) at 13:31, 11 May 2006 (Retouched the phrase that said goto statements aren't faster than gosubs). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Unstructured programming is a programming paradigm where all code is contained in a single continuous block. This is contrary to structured programming, where programmatic tasks are split into smaller sections (known as functions or subroutines) that can be called whenever they are required. Unstructured programming languages have to rely on execution flow statements such as Goto, used in many languages to jump to a specified section of code.

Unstructured source code is notoriously difficult to read and debug, and so is discouraged in programming languages that support any kind of structure. However, structure is not needed in any programming language since program structures can always be implemented by a combination of conditional statements and Goto statements. Unstructured programming is still used in some scripting languages such as MS-DOS batch files, older programming languages such as BASIC or FORTRAN. Despite Goto statements may have a small performance benefit compared to procedure calls, current CPU architectures have made them negligible. In fact, the use of Goto statements may often be harmful if they obfuscate things that the compiler could otherwise optimize.

Assembly language is mostly an unstructured language, because the underlying machine code never has structure. The only structure it has describes things required by compilation tools, such as where a function begins and ends.

See also