PROGRAM COMPOSITION

We can distinguish four levels of programme hierarchy:

  1. Blocks.
  2. Routines and sub-programs.
  3. Scope rules.
  4. Modules, packages and tasks.
  5. Programs.

Two other possible ingredients, which should be discussed here, are Generics and Abstract Data Types (ADTs).




1. BLOCKS


1.1 Block Structured Languages

  • Block structured programming languages allow nesting of blocks. The concept was first introduced in Algol 60 and thus refers to languages where declarations must be made at the start of a procedure or function.
  • Thus Ada, Algol 60 and Pasca are all block structured in the sence that procedure/functions (the smallest possible grouping in these languages) can be nested within other procedures and functions. (C is not a block structured language because procedures/functions cannot be nested).
  • In block structured languages blocks can inherit names declared in enclosing blocks.
  • Variables declared in the outermost block are global variables that are said to have global scope (they can be "seen" from anywhere in the program).
BLOCK STRUCTURE

Block structure




2. SUB-PROGRAMS (ROUTINES)

One of the most important issues that has to be addressed in the design of a programming language is the support it gives to the control of complexity. An important technique is the division of a program into "chunks", called routines or sub-programs, that will allow the programmer to think at a more abstract level. At its simplest a routine can be equivalent to a block. More specifically a routine can be defined as a collection of declarations and statements that must be invoked explicitly (routine invocation). Note that after invocation control is returned to the point immediately after the invocation. An additional advantage is that routines can be stored in libraries for reuse.

Further Issues involved include: