Nesting (computing)
Encyclopedia
In computing science and informatics
Informatics (academic field)
Informatics is the science of information, the practice of information processing, and the engineering of information systems. Informatics studies the structure, algorithms, behavior, and interactions of natural and artificial systems that store, process, access and communicate information...

, the word nesting may denote several different constructions and activities where information is organized in layers or objects contain other similar objects. The rather general term is thus used in quite specific ways for various situations and concepts depending on context, which is sometimes only remotely related. However, it almost always refer to self-similar
Self-similarity
In mathematics, a self-similar object is exactly or approximately similar to a part of itself . Many objects in the real world, such as coastlines, are statistically self-similar: parts of them show the same statistical properties at many scales...

 or recursive
Recursive
Recursive may refer to:*Recursion, the technique of functions calling themselves*Recursive function, a total computable function*Recursive language, a language which is decidable...

 structures in some sense.

The word has been used to denote:
  • nested calls:
    • using several levels of subroutine
      Subroutine
      In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

      s
    • recursive call
      Recursion (computer science)
      Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem. The approach can be applied to many types of problems, and is one of the central ideas of computer science....

      s
  • nested levels of parentheses in arithmetic expressions
  • nested blocks of imperative source code
    Source code
    In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

     such as nested if-clauses, while-clauses, repeat-until clauses etc
  • information hiding
    Information hiding
    In computer science, information hiding is the principle of segregation of the design decisions in a computer program that are most likely to change, thus protecting other parts of the program from extensive modification if the design decision is changed...

    :
    • nested function definitions
      Nested function
      In computer programming, a nested function is a function which is lexically encapsulated within another function. It can only be called by the enclosing function or by functions directly or indirectly nested within the same enclosing function. In other words, the scope of the nested function is...

       with lexical scope
    • nested data structures such as records, objects, classes, etc
  • nested virtualization, also called recursive virtualization: running a virtual machine
    Virtual machine
    A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...

     inside another virtual machine

In spreadsheets

In a spreadsheet
Spreadsheet
A spreadsheet is a computer application that simulates a paper accounting worksheet. It displays multiple cells usually in a two-dimensional matrix or grid consisting of rows and columns. Each cell contains alphanumeric text, numeric values or formulas...

 functions can be nested one into another, making complex formulas. The function wizard of the OpenOffice.org
OpenOffice.org
OpenOffice.org, commonly known as OOo or OpenOffice, is an open-source application suite whose main components are for word processing, spreadsheets, presentations, graphics, and databases. OpenOffice is available for a number of different computer operating systems, is distributed as free software...

 Calc
OpenOffice.org Calc
OpenOffice.org Calc is the spreadsheet component of the OpenOffice.org software package.Calc is similar to Microsoft Excel, with a roughly equivalent range of features. Calc is capable of opening and saving most spreadsheets in Microsoft Excel file format...

 application allows to navigate through multiple levels of nesting, letting the user to edit (and possibly correct) each one of them separately. The popular Microsoft Excel
Microsoft Excel
Microsoft Excel is a proprietary commercial spreadsheet application written and distributed by Microsoft for Microsoft Windows and Mac OS X. It features calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic for Applications...

 doesn't support this particular feature, which is particularly useful when working with big sheets.

Naturally, to allow the mathematical resolution of these chained (or better: nested) formulas, the inner expressions must be previously evaluated, and this outward direction is essential because the results that the internal functions return are temporarily used as entry data for the external ones.

Due to the potential accumulation of parentheses in only one code line, editing and error detecting (or debugging
Debugging
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected. Debugging tends to be harder when various subsystems are tightly coupled, as changes in one may cause bugs to emerge...

) can became somehow awkward. That is why modern programming environments -as well as spreadsheet programs- highlight in bold type the pair corresponding to the current editing position. The (automatic) balancing control of the opening and closing parenthesis known as brace match checking.

In programming

In structured programming
Structured programming
Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could...

 languages, nesting is related to the enclosing of control structures
Control flow
In computer science, control flow refers to the order in which the individual statements, instructions, or function calls of an imperative or a declarative program are executed or evaluated....

 one into another, usually indicated through different indentation levels within the source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

, as it is shown in this simple BASIC
BASIC
BASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....

 function:


function LookupCode(code as string) as integer
dim sLine, path as string
dim return_value as integer

path="C:\Test.csv"
if FileExists(path) then
open path for input as #1
do while not EOF(1)
line input #1, sLine
if left(sLine, 3)=code then
'Action(s) to be carried out
End if
loop
close #1
LookupCode=return_value
end function


In this small and simple example, the conditional block “if... then... end if” is nested inside the “do while... loop” one.

Some languages such as Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...

 and Ada
Ada (programming language)
Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...

 have no restrictions on declarations depending on the nesting level, allowing precisely nested subprograms or even nested packages (Ada). Here is an example of both (simplified from a real case):


-- Getting rid of the global variables issue (cannot be used in parallel)
-- from a set of old sources, without the need to change that code's
-- logic or structure.
--
procedure Nesting_example_1 is

type Buffer_type is array(Integer range <>) of Integer;

procedure Decompress(
compressed : in Buffer_type;
decompressed: out Buffer_type
)
is
-- Here are the legacy sources, translated:
package X_Globals is
index_in, index_out: Integer;
-- *** ^ These variables are local to Decompress.
-- *** Now Decompress is task-safe.
end X_Globals;
-- Methods 1,2,3,... (specifications)
package X_Method_1 is
procedure Decompress_1;
end X_Method_1;
-- Methods 1,2,3,... (code)
package body X_Method_1 is
use X_Globals;
procedure Decompress_1 is
begin
index_in:= compressed'First;
-- Here, the decompression code, method 1
end Decompress_1;
end X_Method_1;
-- End of the legacy sources
begin
X_Method_1.Decompress_1;
end Decompress;

test_in, test_out: Buffer_type(1..10_000);

begin
Decompress(test_in, test_out);
end Nesting_example_1;

See also

  • Flow control
    Flow control
    In data communications, flow control is the process of managing the pacing of data transmission between two nodes to prevent a fast sender from outrunning a slow receiver. It provides a mechanism for the receiver to control the transmission speed, so that the receiving node is not overwhelmed with...

  • For loop
    For loop
    In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement....

  • Function
  • Procedure
  • Pseudocode
    Pseudocode
    In computer science and numerical computation, pseudocode is a compact and informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading...

  • Structured programming
    Structured programming
    Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK