next up previous contents
Next: Naming of Variables Up: Programming Style Previous: Organization of Source Code   Contents

Formatting the Code

By formatting, we mean how many spaces to indent, when to indent, how to match up braces, when to use capital vs. lower case letters, and so forth. This is perhaps a more subjective matter than those previously discussed. However, it is certainly true that some formatting styles are easier to read than others. For already existing code, we recommend that you conform to the formatting convention already present in the code. The author of the code is likely to get upset when he sees that you're incorporated code fragments with a formatting style which differs from his! On the other hand, in certain rare cases, it might be more beneficial to incorporate a different style: in the conversion of intder95 from old-style to new-style input, we used lower-case lettering instead of the all-caps style of the original program. This was very useful in helping us locate which changes we had made.

It is very common that statements within loops are indented. Loops within loops are indented yet again, and so on. This practice is near-universal and very helpful. Computational chemistry programs often require many nested loops. The consequence of this is that lines can be quite long, due to all those spaces before each line in the innermost loops. If the lines become longer than 80 characters, they are hard to read within a single window; please try to keep your lines to 80 characters or less. This means that you should use about 2-4 spaces per indentation level.

The matching of braces, and so forth, is more variable, and we recommend you follow the convention of The C Programming Language, by Kernighan and Ritchie, or perhaps the style found in other PSI3modules.


next up previous contents
Next: Naming of Variables Up: Programming Style Previous: Organization of Source Code   Contents
psi 2003-01-07