21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

92 Chapter 7 ■ Structured programming<br />

Ease of reading (static and dynamic structures)<br />

In the Western world we are used to reading left to right and top to bottom. To have to<br />

begin by reading <strong>for</strong>wards and then to have to go backwards in the text is rather unnatural;<br />

it is simpler if we can always continue onwards. It is an important feature of a structured program<br />

that it can always be read from top to bottom – provided it has no methods. The exception<br />

to this rule arises in comprehending a while loop, during which repeated references<br />

back to the terminating condition at the start of the loop are necessary.<br />

Programs are essentially dynamic beings that exhibit a flow of control, while the program<br />

listing is a static piece of text. To ease understanding, the problem is to bring the<br />

two into harmony – to have the static text closely reflect the dynamic execution. In a<br />

structured program, the flow of control is always down the page, which exactly corresponds<br />

to the way that text is normally read.<br />

Proving programs correct<br />

Formally to prove all programs correct is not a practical proposition with present-day<br />

techniques. Nonetheless there are some lessons that can be learned from proving.<br />

In one technique of program proving, assertions are made at strategic points in the<br />

program. An assertion is a statement of what things are true at that point in the program.<br />

More exactly, an assertion describes the relationships that hold between data<br />

items that the program acts upon. Assertions at the start and end of a piece of program<br />

are called the input and output assertions respectively. Proving consists of rigorously<br />

demonstrating that if the input assertion is true, then the action of the program will<br />

lead to the output assertion being true.<br />

A structured program consists solely of components that have a single entry and a<br />

single exit point. This considerably aids the process of reasoning about the effect of the<br />

program. In contrast, it is usually impossible to isolate single-entry, single-exit structures<br />

within a program with gotos in it.<br />

Even when <strong>for</strong>mal proof techniques are not being used, but where an in<strong>for</strong>mal study<br />

of the program is being made, the single-entry and single-exit character of programs<br />

aids checking and understanding.<br />

7.3 ● Arguments in favor of goto<br />

Deskilling<br />

The goto statement is one tool among many provided by the programming language. To<br />

take it away from the programmer is to deprive him or her of a tool that can be validly<br />

used in certain circumstances.<br />

Consider a craftsperson who is an expert at making delicate objects from wood.<br />

Suppose that we remove from that person a tool that we consider to be inappropriate,<br />

say an ax. The skill of making a discriminating selection among the available tools is<br />

reduced, because the choice is narrower. Furthermore, the skill in using the tool is no

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!