Caribbean Secondary Education Certificate - Information Technology/Structured Programming Techniques

From WikiEducator
Jump to: navigation, search

Introduction to Structured Programming

Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO statement.

Historically, several different structuring techniques or methodologies have been developed for writing structured programs. The most common are:

  • Edsger Dijkstra's structured programming, where the logic of a program is a structure composed of similar sub-structures in a limited number of ways. This reduces understanding a program to understanding each structure on its own, and in relation to that containing it, a useful separation of concerns.
  • A view derived from Dijkstra's which also advocates splitting programs into sub-sections with a single point of entry, but is strongly opposed to the concept of a single point of exit.
  • Data Structured Programming or Jackson Structured Programming, which is based on aligning data structures with program structures. This approach applied the fundamental structures proposed by Dijkstra, but as constructs that used the high-level structure of a program to be modeled on the underlying data structures being processed. There are at least 3 major approaches to data structured program design proposed by Jean-Dominique Warnier, Michael A. Jackson, and Ken Orr.

The two latter meanings for the term "structured programming" are more common, and that is what this article will discuss. Years after Dijkstra (1969), object-oriented programming (OOP) was developed to handle very large or complex programs


Low-Level Structure

At a low level, structured programs are often composed of simple, hierarchical program flow structures. These are concatenation, selection, and repetition:

  • "Concatenation" refers to a sequence of statements executed in order.
  • In "selection" one of a number of statements is executed depending on the state of the program. This is usually expressed with keywords such as if..then..else..endif, switch, or case.
  • In "repetition" a statement is executed until the program reaches a certain state or operations are applied to every element of a collection. This is usually expressed with keywords such as while, repeat, for or do..until. Often it is recommended that each loop should only have one entry point (and in the original structural programming, also only one exit point), and a few languages enforce this.

Some languages, such as Dijkstra's original Guarded Command Language, emphasise the unity of these structures with a syntax which completely encloses the structure, as in if..fi. In others, such as C, this is not the case, which increases the risk of misunderstanding and incorrect modification.

A language is described as "block-structured" when it has a syntax for enclosing structures between bracketed keywords, such as an if-statement bracketed by if..fi as in ALGOL 68, or a code section bracketed by BEGIN..END, as in PL/I. However, a language is described as "comb-structured" when it has a syntax for enclosing structures within an ordered series of keywords. A "comb-structured" language has multiple structure keywords to define separate sections within a block, analogous to the multiple teeth or prongs in a comb separating sections of the comb. For example, in Ada, a block is a 4-pronged comb with keywords DECLARE, BEGIN, EXCEPTION, END, and the if-statement in Ada is a 4-pronged comb with keywords IF, THEN, ELSE, END IF.


Design

Structured programming is often (but not always) associated with a "top-down" approach to design.

What is Top-down approach to design Top-down and bottom-up are strategies of information processing and knowledge ordering, mostly involving software, but also other humanistic and scientific theories (see systemics). In practice, they can be seen as a style of thinking and teaching. In many cases top-down is used as a synonym of analysis or decomposition, and bottom-up of synthesis.

A top-down approach is essentially breaking down a system to gain insight into its compositional sub-systems. In a top-down approach an overview of the system is first formulated, specifying but not detailing any first-level subsystems. Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. A top-down model is often specified with the assistance of "black boxes" that make it easier to manipulate. However, black boxes may fail to elucidate elementary mechanisms or be detailed enough to realistically validate the model.

A bottom-up approach is piecing together systems to give rise to grander systems, thus making the original systems sub-systems of the emergent system. In a bottom-up approach the individual base elements of the system are first specified in great detail. These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed. This strategy often resembles a "seed" model, whereby the beginnings are small but eventually grow in complexity and completeness. However, "organic strategies" may result in a tangle of elements and subsystems, developed in isolation and subject to local optimization as opposed to meeting a global purpose.

Advantages of top-down programming

  • Separating the low level work from the higher level objects leads to a modular design.
  • Modular design means development can be self contained.
  • Having "skeleton" code illustrates clearly how low level modules integrate.
  • Fewer operations errors (to reduce errors, because each module has to be processed separately, so programmers get large amount of time for processing).
  • Much less time consuming (each programmer is only involved in a part of the big project).
  • Very optimized way of processing (each programmer has to apply their own knowledge and experience to their parts (modules), so the project will become an optimized one).
  • Easy to maintain (if an error occurs in the output, it is easy to identify the errors generated from which module of the entire program).

Disadvantages of top-down programming

  • Functionality either needs to be inserted into low level objects by making them return "canned answers"—manually constructed objects, similar to what you would specify if you were mocking them in a test, or otherwise functionality will be lacking until development of low level objects is complete.


BottomUp Approach

In a bottom-up approach the individual base elements of the system are first specified in great detail. These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed. This strategy often resembles a "seed" model, whereby the beginnings are small, but eventually grow in complexity and completeness.

Object-oriented programming (OOP) is a programming paradigm that uses "objects" to design applications and computer programs.

In Mechanical Engineering with software programs such as Pro/ENGINEER and Solidworks users can design products as pieces not part of the whole and later add those pieces together to form assemblies like building LEGOS. Engineers call this piece part design.

Pro/ENGINEER WF4.0 proetools.com - Lego Racer Pro/ENGINEER Parts is a good example of BottomUp because the parts are first created and then assembled without regard to how the parts will work in the assembly.This bottom-up approach has one weakness. We need to use a lot of intitution to decide the functionality that is to be provided by the module. If a system is to be built from existing system,this approach is more suitable as it starts from some existing modules.

Structured Programming Languages

It is possible to do structured programming in any programming language, though it is preferable to use something like a procedural programming language. Since about 1970 when structured programming began to gain popularity as a technique, most new procedural programming languages have included features to encourage structured programming (and sometimes have left out features that would make unstructured programming easy). Some of the better known structured programming languages are ALGOL, Pascal, PL/I and Ada.

Reference: [1] [2]