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.

94 Chapter 7 ■ Structured programming<br />

><br />

-----<br />

----endif<br />

which requires an additional test. Although both programs achieve the same end – finding<br />

(or not finding) the desired item – the steps taken by the two programs differ. The first<br />

(unstructured) program takes fewer steps, and there is no way of writing a structured program<br />

that works in the same way. Thus it is possible to write goto programs that run<br />

more quickly than structured ones.<br />

Naturalness<br />

Consider the table searching program above. Arguably the unstructured solution is the<br />

best in the sense that it is the solution that solves the problem most naturally. Any trans<strong>for</strong>mation<br />

of this program, or any other solution, is a distortion of the natural solution.<br />

In other words, getting rid of gotos in existing programs (as can always be done), will<br />

sometimes needlessly destroy a good program.<br />

The trouble is deciding what is natural. It surely differs from person to person,<br />

depending on individual psychology and cultural experiences. So it is a rather subjective<br />

judgment.<br />

7.4 ● Selecting control structures<br />

Rather than take part in a parochial debate about the merits of a particular control<br />

structure, let us take a constructive approach. If we had a free choice and a blank piece<br />

of paper, what control structures would we choose to use in programming? Perhaps our<br />

first consideration should be to establish the principles that govern the selection. Let us<br />

examine the following criteria:<br />

■ standardization<br />

■ abstraction<br />

■ expressive power<br />

■ orthogonality<br />

■ minimality.<br />

We shall see that some of these conflict with each other. Note also that in our examination<br />

we are confining ourselves to sequential, imperative programming, in contrast to<br />

concurrent or declarative programming (as in logic or functional programming).<br />

Standardization<br />

Domestic appliances exhibit enormous variety and yet all plug into a standard socket.<br />

Similarly, it is desirable to build software from components that all exhibit the same<br />

external interface.

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

Saved successfully!

Ooh no, something went wrong!