Jackson structured programming (Ofer Abarbanel online library)

Jackson structured programming (JSP) is a method for structured programming developed by British software consultant Michael A. Jackson and described in his 1975 book Principles of Program Design.[1] The technique of JSP is to analyze the data structures of the files that a program must read as input and produce as output, and then produce a program design based on those data structures, so that the program control structure handles those data structures in a natural and intuitive way.

JSP describes structures (of both data and programs) using three basic structures— sequence, iteration, and selection (or alternatives). These structures are diagrammed as (in effect) a visual representation of a regular expression.

Introduction

Michael A. Jackson originally developed JSP in the 1970s. He documented the system in his 1975 book Principles of Program Design.[1] In a 2001 conference talk,[2] he provided a retrospective analysis of the original driving forces behind the method, and related it to subsequent software engineering developments. Jackson’s aim was to make COBOL batch file processing programs easier to modify and maintain, but the method can be used to design programs for any programming language that has structured control constructs— sequence, iteration, and selection (“if/then/else”).

Jackson Structured Programming was similar to Warnier/Orr structured programming[3][4] although JSP considered both input and output data structures while the Warnier/Orr method focused almost exclusively on the structure of the output stream.

Motivation for the method

At the time that JSP was developed, most programs were batch COBOL programs that processed sequential files stored on tape. A typical program read through its input file as a sequence of records, so that all programs had the same structure— a single main loop that processed all of the records in the file, one at a time. Jackson asserted that this program structure was almost always wrong, and encouraged programmers to look for more complex data structures. In Chapter 3 of Principles of Program Design[1] Jackson presents two versions of a program, one designed using JSP, the other using the traditional single-loop structure. Here is his example, translated from COBOL into Java. The purpose of these two programs is to recognize groups of repeated records (lines) in a sorted file, and to produce an output file listing each record and the number of times that it occurs in the file.

Here is the traditional, single-loop version of the program.

String line;

int count = 0;

String firstLineOfGroup = null;

 

// begin single main loop

while ((line = in.readLine()) != null) {

if (firstLineOfGroup == null || !line.equals(firstLineOfGroup)) {

if (firstLineOfGroup != null) {

System.out.println(firstLineOfGroup + ” ” + count);

}

count = 0;

firstLineOfGroup = line;

}

count++;

}

if (firstLineOfGroup != null) {

System.out.println(firstLineOfGroup + ” ” + count);

}

Here is a JSP-style version of the same program. Note that (unlike the traditional program) it has two loops, one nested inside the other. The outer loop processes groups of repeating records, while the inner loop processes the individual records in a group.

String line;

int numberOfLinesInGroup;

 

line = in.readLine();

//begin outer loop: process 1 group

while (line != null) {

numberOfLinesInGroup = 0;

String firstLineOfGroup = line;

 

//begin inner loop: process 1 record in the group

while (line != null && line.equals(firstLineOfGroup)) {

numberOfLinesInGroup++;

line = in.readLine();

}

System.out.println(firstLineOfGroup + ” ” + numberOfLinesInGroup);

}

Jackson criticises the traditional single-loop version for failing to process the structure of the input file (repeating groups of records containing repeating individual records) in a natural way. One sign of its unnatural design is that, in order to work properly, it is forced to include special code for handling the first and last record of the file.

Techniques for handling difficult design problems

In Principles of Program Design Jackson recognized situations that posed specific kinds of design problems, and provided techniques for handling them.

One of these situations is a case in which a program processes two input files, rather than one. In 1975, one of the standard “wicked problems” was how to design a transaction-processing program. In such a program, a sequential file of update records is run against a sequential master file, producing an updated master file as output. (For example, at night a bank would run a batch program that would update the balances in its customers’ accounts based on records of the deposits and withdrawals that they had made that day.) Principles of Program Design provided a standard solution for that problem, along with an explanation of the logic behind the design.

Another kind of problem involved what Jackson called “recognition difficulties” and today we would call parsing problems. The basic JSP design technique was supplemented by POSIT and QUIT operations to allow the design of what we would now call a backtracking parser.

JSP also recognized three situations that are called “structure clashes”— a boundary clash, an ordering clash, and an interleaving clash— and provided techniques for dealing with them. In structure clash situations the input and output data structures are so incompatible that it is not possible to produce the output file from the input file. It is necessary, in effect, to write two programs— the first processes the input stream, breaks it down into smaller chunks, and writes those chunks to an intermediate file. The second program reads the intermediate file and produces the desired output.

JSP and object-oriented design

JSP was developed long before object-oriented technologies became available. It and its successor method JSD do not treat what now would be called “objects” as collections of more or less independent methods. Instead, following the work of C A R Hoare, JSP and JSD describe software objects as co-routines.[5][6]

References

  1. ^ Jump up to:ab c Jackson, MA (1975), Principles of Program Design, Academic.
  2. ^Jackson, MA (2001), JSP in Perspective (PDF), sd&m Pioneers’ Conference, Bonn, June 2001, retrieved 2017-01-26
  3. ^Warnier, JD (1974), Logical Construction of Programs, NY: Van Nostrand Reinhold
  4. ^Orr, KT (1980), “Structured programming in the 1980s”, Proceedings of the ACM 1980 Annual Conference, New York, NY: ACM Press, pp. 323–26, doi:10.1145/800176.809987, ISBN 978-0897910286

Ofer Abarbanel – Executive Profile

Ofer Abarbanel online library

Ofer Abarbanel online library

Ofer Abarbanel online library

Ofer Abarbanel online library