Supriya Ghosh (Editor)

Nesting (computing)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

In computing science and informatics, nesting is where information is organized in layers, or where objects contain other similar objects. It almost always refers to self-similar or recursive structures in some sense.

Contents

Nesting can mean:

  • nested calls:
  • using several levels of subroutines
  • recursive calls
  • nested levels of parentheses in arithmetic expressions
  • nested blocks of imperative source code such as nested if-clauses, while-clauses, repeat-until clauses etc.
  • information hiding:
  • nested function definitions with lexical scope
  • nested data structures such as records, objects, classes, etc.
  • nested virtualization, also called recursive virtualization: running a virtual machine inside another virtual machine
  • In spreadsheets

    In a spreadsheet functions can be nested one into another, making complex formulas. The function wizard of the OpenOffice.org Calc application allows to navigate through multiple levels of nesting, letting the user to edit (and possibly correct) each one of them separately.

    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) 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 languages, nesting is related to the enclosing of control structures one into another, usually indicated through different indentation levels within the source code, as it is shown in this simple BASIC 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 and Ada 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):

    References

    Nesting (computing) Wikipedia