Reg is president of Charney & Day. He can be reached on CompuServe at 70272,3427 or at charney@pipeline.com.
Software Development with Z, by J.B. Wordsworth, is an introduction to modern-day formal methods and their practicality for software development. Although Wordsworth uses only the Z specification language (supported by a variant of Dijkstra's guarded command language), you still get a good sense for strongly typed specification languages. The book also serves as a tutorial on formal methods in general and the Z language in particular.
While the book is easily read and understood, you do need to familiarize yourself with set theory and its notation, since Z uses more than 90 different symbols, most of which are nonmnemonic and unavailable in any normal typeface. Some operators are overloaded, and the naming conventions are not always helpful. For example, names like je1 and k1 are used instead of b1 and b2.
Software Development with Z starts out by covering the basics of discrete mathematics: sets, logic, and relationships. It then examines Z schema and the guarded command language and finally discusses design and implementation issues.
Wordsworth uses two examples throughout the book. One discusses a library, its books, and the people borrowing them, while the second is based on school classes and people enrolled in them. The examples are discussed informally at first, and are developed more rigorously as the book progresses. This approach maintains coherence and makes the book easy to follow. A complete application appears at the end of the book, less the actual code.
There are exercises at the end of each chapter, with answers for most of the questions. There's also an appendix containing a bibliography and a complete list of all special symbols used in Z.
Z lets you record software specifications, data design, and algorithmic implementation decisions. It is not a programming language, and is best used for defining specifications, rather than designs.
More specifically, Z is a mathematical software-specification language developed in the 1970s at Oxford University in England. In the early 1980s, software developers at IBM's Hursley Research Centre started working on Z, releasing commercial CICS online-transaction software for banks and airlines in the early 1990s. Wordsworth was a part of IBM's original Z development team.
Figures 1 through 4 show schema specifications in Z. The first line always declares the schema name. The remaining lines in the upper part of the schema declare data types used in the schema. The lower part of the schema consists of the predicates that must be true for the schema to be valid.
Figure 1 is a typical schema specification. It defines the starting conditions that must exist for an oil-terminal control system. The following are the interpretations of the code by line number:
For Figure 3:
Given these schema, you can write this logical equation in Z:ArrivedOK
Docked
Queued. Because Z is only a specification language, Dijkstra's guarded command language is used to implement the specifications. This language consist of statements having two parts, a guard and a command, separated by a
sign. The command is executed only if the guard expression is true. For example, to increment a variable x by 1, we would normally write x:=x+1. In the guarded command language, you would write x<MAX_INT
x:=x+1, which states that the increment operation is valid only if the current value of x is less than the maximum allowable integer value.
The guarded command language has three control structures: sequence, alternation, and iteration. These control structures are made up of constructs, each of which consists of a guard expression and a body. A guard expression must be true for the body of the statement to be executed. Either the guard or the body can be omitted.
Wordsworth emphasizes that formal methods are part of a social process of software development, which should include a group of people representing various parts of the development cycle. Formal methods are not means for developing software without difficult decisions, says Wordsworth, but are methods for recording those decisions once made. Z documents consist principally of English text with small pieces of mathematical formalisms.
I highly recommend the beautifully written section on writing good specifications, as well as Wordsworth's description of how to verify a specification. Verification is part of the testing process. His comments on testing are reminiscent of one of Edward Yourdon's main points in Decline and Fall of the American Programmer (Prentice Hall, 1991): Tracking bugs is important, not just to fix problems, but to modify the processes that created them.
Software Development with Z achieves its three principal aims: To encourage programmers to explore the use of formal methods in perfecting their craft, to provide an insight into the practical problems of applying mathematics to real software development, and to explain the features of Z.
Figure 1 Starting conditions for an oil-terminal control system.
Figure 3 Tanker is docked.
Figure 2 Condition for arriving Tankers.
Figure 4 Tanker is queued.
Copyright © 1995, Dr. Dobb's Journal