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

Create successful ePaper yourself

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

Effective Programming: The<br />

Polymorphic Way<br />

Chapter 7<br />

Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove<br />

it.<br />

—Alan Perlis<br />

To remove complexity in scientific application development (but not only there), several programming<br />

techniques, methods, and application of paradigms have to be used accordingly. This<br />

not only depends on the ability to combine application-specific functionality with other librarycode<br />

from a variety of sources but also to restrict the amount of application-specific glue code.<br />

So libraries must remain open <strong>for</strong> extension but closed <strong>for</strong> modification, which can be attributed<br />

to a technique called polymorphic programming.<br />

The presented sections of this book introduced important mechanisms to successfully develop<br />

scientific applications such as <strong>C++</strong> basics, encapsulation, generic and meta programming as<br />

well as inheritance. An important part of scientific computing, matrix containers and matrix<br />

algorithms, has been presented to aid the topics so far. Effective programming is then possible if<br />

these mechanisms are not viewed as separate entities, but as different characteristics to achieve<br />

important goals, such as<br />

• uncompromising efficiency of simple basic operations (e.g., array subscripting should not<br />

incur the cost of a function call),<br />

• type-safety (e.g., an object from a container should be usable without explicit or implicit<br />

type conversion),<br />

• code reuse and extensibility,<br />

all with their respective advantages and disadvantages. This section reviews important techniques<br />

to achieve polymorphism from a more general point of view and highlights a basic but<br />

very important recurring principle <strong>for</strong> scientific computing: code reusability. This is not mainly<br />

because programmers are lazy people, but also because applications have to be tested. For<br />

the field of scientific applications this is particularlly important due to large parameter sets,<br />

changing boundary and initial conditions, as well as long run-times of simulation codes. Hence<br />

it should not be underestimated how much time and ef<strong>for</strong>t can be saved, if already tested code<br />

can be used as starting point or reference. So code reusability is not only about programming<br />

less, but also because of extend code quality. Most of the presented and discussed technique so<br />

199

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

Saved successfully!

Ooh no, something went wrong!