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.

72 Chapter 6 ■ Modularity<br />

a program is necessary during architectural design, verification, debugging and maintenance,<br />

and it is there<strong>for</strong>e an important activity. When studying software we cannot<br />

look at the whole software at once because (<strong>for</strong> software of any practical length) it is<br />

too complex to comprehend as a whole.<br />

When we need to understand the overall structure of software (e.g. during design or<br />

during maintenance), we need large components. On other occasions (e.g. debugging)<br />

we need to focus attention on an individual component. For this purpose a small component<br />

is preferable. If the software has been well designed, we can study the logic of<br />

an individual component in isolation from any others. However, as part of the task of<br />

studying a component we need to know something about any components it uses. For<br />

this purpose the power of abstraction is useful, so that while we understand what other<br />

components do, we do not need to understand how they do it. There<strong>for</strong>e, ideally, we<br />

never need to comprehend more than one component at a time. When we have completed<br />

an examination of one component, we turn our attention to another. There<strong>for</strong>e,<br />

we conclude, it is the size and complexity of individual components and their connections<br />

with other components that is important.<br />

This discussion assumes that the software has been well constructed. This means<br />

that abstraction can be applied in understanding an individual component. However,<br />

if the function of a component is not obvious from its outward appearance, then we<br />

need to delve into it in order to understand what it does. Similarly, if the component<br />

is closely connected to other components, it will be difficult to understand in isolation.<br />

We discuss these issues later.<br />

Small components can give rise to slower programs because of the increased overhead<br />

of method calls. But nowadays a programmer’s time can cost significantly more<br />

than a computer’s time. The question here is whether it is more important <strong>for</strong> a program<br />

to be easy to understand or whether it is more important <strong>for</strong> it to run quickly.<br />

These requirements may well conflict and only individual circumstances can resolve the<br />

issue. It may well be better, however, first to design, code and test a piece of software<br />

using small components, and then, if per<strong>for</strong>mance is important, particular methods that<br />

are called frequently can be rewritten in the bodies of those components that use them.<br />

It is, however, unlikely that method calls will adversely affect the per<strong>for</strong>mance of a program.<br />

Similarly, it is unlikely that encoding methods in-line will give rise to significant<br />

improvement. Rather, studies have shown that programs spend most of their time<br />

(about 50%) executing a small fraction (about 10%) of the code. It is the optimization<br />

of these small parts that will give rise to the best results.<br />

In the early days of programming, main memory was small and processors were slow. It<br />

was considered normal to try hard to make programs efficient. One effect of this was that<br />

programmers often used tricks. Nowadays the situation is rather different – the pressure is<br />

on to reduce the development time of programs and ease the burden of maintenance.<br />

So the emphasis is on writing programs that are clear and simple, and there<strong>for</strong>e easy to<br />

check, understand and modify.<br />

What are the arguments <strong>for</strong> simplicity?<br />

■ it is quicker to debug a simple program<br />

■ it is quicker to test a simple program

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

Saved successfully!

Ooh no, something went wrong!