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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

90 Chapter 7 ■ Structured programming<br />

><br />

listing of a program that is written in a structured way and asked a series of questions<br />

that are designed to assess their comprehension of it. The accuracy of the replies and<br />

the time taken to reply are both measured. These are measures of the ease with which<br />

the program could be debugged or changed. A second group of subjects are given<br />

copies of the same program rewritten in an unstructured way. The accuracy and<br />

response times of the two groups are compared. The results of these experiments generally<br />

indicate that structured programs are superior to unstructured ones.<br />

The results of empirical studies are reviewed in the literature given at the end of<br />

the chapter. In a review published in 1984, long after the dust had settled on the<br />

structured programming debate, Vessey and Weber concluded that “the evidence<br />

supporting [structured programming] is weak”. This conclusion largely stems from<br />

the difficulty of carrying out experiments that give trustworthy results.<br />

Clarity and expressive power<br />

Compare the following two equivalent program fragments:<br />

------ -------<br />

------ ------label:<br />

while a > 0<br />

------ -------<br />

------ ------if<br />

a > 0 goto label endwhile<br />

------ -------<br />

------ -------<br />

As we read down the first program fragment, we are not immediately sure what the<br />

roles of the label and goto are. It would take us some time to read and study the program<br />

in order to discover that they are being used to create the repetition of a piece of<br />

code. This is made immediately obvious by the while statement in the second program.<br />

Worse, there is a remaining doubt in the first program that there may be another<br />

goto aimed at this same label from some other point in the program.<br />

The facilities of a programming language should allow people to describe what they<br />

want to do in a meaningful way. If we examine a typical program written using gotos<br />

we see that the gotos are used <strong>for</strong> a variety of purposes, <strong>for</strong> example:<br />

■ to avoid a piece of code (which is to be executed in different circumstances)<br />

■ to per<strong>for</strong>m repetition<br />

■ to exit from the middle of a loop<br />

■ to invoke a shared piece of code.<br />

When we see a goto, there are few clues that allow us to decide the purpose <strong>for</strong><br />

which the goto is being used. The alternative is, of course, a unique language construct<br />

<strong>for</strong> use in each of these different circumstances. These are, respectively:<br />

>

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

Saved successfully!

Ooh no, something went wrong!