03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

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.

7.1. IMPERATIVE PROGRAMMING 201<br />

7.1 Imperative Programming<br />

Imperative programming may be viewed as the very bones on which all other abstractions<br />

depend. This programming paradigm uses a sequence of instructions which act on a state to<br />

realize algorithms. Thus it is always specified in detail what and how to execute next. The<br />

modification of the program state while convenient is also an issue, as with increasing size of<br />

the program, unintended modifications of the state becomes an increasing problem. In order<br />

to address this issue the imperative programming method has been refined to procedural and<br />

structured programming paradigms, which attempt to provide more control of the modifications<br />

of the program state. Hence it is based upon organized procedure calls. Procedure calls, also<br />

known as routines, subroutines, methods, or functions simply contain a series of computational<br />

steps to be carried out. Any given procedure might be called at any point during a program’s<br />

execution, including other procedures or itself. A function consists of:<br />

• The return type of the function: A function returns the value at a user specified position.<br />

C or C ++ which does not provide procedures explicitely has to use the keyword void <strong>for</strong><br />

indicating that a function does not return a value.<br />

• The name of the function: Therewith the function can be called. The name should be as<br />

expressive possible. Never underestimate names with good significance.<br />

• The parameter list of the function: The parameters of a function serve as placeholders<br />

<strong>for</strong> values that are later supplied by the user during each invocation of the function. A<br />

function can have an empty parameter list. The values of the parameter list can be given<br />

by value or by reference.<br />

• The body of the function: The body of a function implements the logic of the operation.<br />

Typically, it manipulates the named parameters of the function.<br />

The advantages of this paradigm are:<br />

• Few techniques<br />

• Rapid prototyping <strong>for</strong> easy problems<br />

• Functions can be put into a library<br />

• Fast compilation<br />

The disadvantages of this paradigm are:<br />

• Test ef<strong>for</strong>t is high<br />

• Source of error is manifold<br />

• Non-trivial problems cause high programming line ef<strong>for</strong>t<br />

• No user defined data types<br />

• No locality of data<br />

• Only very few and simple functions can be put into a library<br />

Even in the refined <strong>for</strong>m as procedural programming the incurred overhead can be limited to a<br />

bare minimum as the level of abstraction is relatively low. This was well suited <strong>for</strong> the situation

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

Saved successfully!

Ooh no, something went wrong!