#Programming_paradigms
#Structured
Structured versus non-structured
Non-structured programming
• Historically the earliest programming paradigm capable of creating #Turing_complete algorithms.
• Uses unstructured control flow construct of GoTo which can lead to "spaghetti code" that is potentially difficult to follow and maintain.
Structured programming
• Aims at improving the clarity, quality, and development time.
• Uses structured control flow constructs of choice and repetition, block structures, and subroutines.
Elements
• Control structures: following the structured program theorem, all programs are seen as composed of control structures of sequence, choice, iteration.
• Blocks: enable groups of statements to be treated as one statement.
• Subroutines: are callable units such as procedures, functions, methods, or subprograms are used to allow a sequence to be referred to by a single statement.
• Recursion: a subroutines is executed by repeatedly calling itself until termination conditions are met. While similar in practice to iterations, recursions may be more efficient.
#Structured
Structured versus non-structured
Non-structured programming
• Historically the earliest programming paradigm capable of creating #Turing_complete algorithms.
• Uses unstructured control flow construct of GoTo which can lead to "spaghetti code" that is potentially difficult to follow and maintain.
Structured programming
• Aims at improving the clarity, quality, and development time.
• Uses structured control flow constructs of choice and repetition, block structures, and subroutines.
Elements
• Control structures: following the structured program theorem, all programs are seen as composed of control structures of sequence, choice, iteration.
• Blocks: enable groups of statements to be treated as one statement.
• Subroutines: are callable units such as procedures, functions, methods, or subprograms are used to allow a sequence to be referred to by a single statement.
• Recursion: a subroutines is executed by repeatedly calling itself until termination conditions are met. While similar in practice to iterations, recursions may be more efficient.
Blocks
- are lexical structures that allow many statements to be treated as one. A language that allows blocks and nested blocks, is called block-structured. Blocks are fundamental to #structured programming.
As scopes
Depending on the language, certain distinguished blocks may be treated as lexical scopes; otherwise, identifiers assigned in outer blocks are visible inside inner blocks, unless shadowed.
Syntax
• Free-form
Whitespace only delimits tokens and has no other significance
•
•
•
• Off-side rule
Indentation groups blocks of code
e.g. #Python, #Haskell, #Cobra, #CoffeeScript
Limitations
In some languages blocks do not fully support all declarations; for instance many C-derived languages do not permit nested functions.
- are lexical structures that allow many statements to be treated as one. A language that allows blocks and nested blocks, is called block-structured. Blocks are fundamental to #structured programming.
As scopes
Depending on the language, certain distinguished blocks may be treated as lexical scopes; otherwise, identifiers assigned in outer blocks are visible inside inner blocks, unless shadowed.
Syntax
• Free-form
Whitespace only delimits tokens and has no other significance
•
begin ... end: #ALGOL, #Pascal•
{ ... }: #C, #Perl, #JS, #Nile•
( keyword ... ): #Lisp• Off-side rule
Indentation groups blocks of code
e.g. #Python, #Haskell, #Cobra, #CoffeeScript
Limitations
In some languages blocks do not fully support all declarations; for instance many C-derived languages do not permit nested functions.