by Nikolai V. Shokhirev
| ABC tutorials |
Up: Scientific programming
Previous: Numerical objects
Next: Project environment
You are a professional, a specialist in your area of expertise. For some reason you have to program in C++. You are not a "C++ guru". However, you already have a huge advantage over any computer scientist or guru: you know what to program. C++, Fortran, Matlab, etc. are just tools in your professional toolset. You simply want to use these tools effectively, probably without knowing all "bells and whistles".
C++ has its specifics. It is a combination of a low-level procedural C, its object-oriented extension, generic (template) extension, and the STL. The polite way to express this is: "C++ is a federation of languages" [1]. The combined grammar is complicated. C++ is error-prone. Its grammar allows doing a lot of stupid things.
Below I collected some rules that help with writing scientific programs in C++. Some of them are actually required by the language, the others are just a good programming practice. I present them without much explanation on a shaman level [2]:

I prefer the term "shamanism" because this is not a high-level doctrine such as Cargo cult programming [3] or Voodoo programming [4]. The rules are not strict as Commandments [5] or Taboo [6]. For example, "Do not use" should be read "Avoid using". I also do not go so far as in [7].
Solver::Solver(int n, int m): grid(n, m), x(n) // initialization of user-defined objects; match declaration order
{
SetDefaults(); // initialization of built-in types
}
if (x = y) {
...
| ABC tutorials |
Up: Scientific programming
Previous: Numerical objects
Next: Project environment
©Nikolai V. Shokhirev, 2004-2008