|
|
Code FormattingTable of contentsIndentationIn order to properly comprehend code indentation is crucial. We recommend the following layout for all new code:
This can be enforced by writing this comment as the first line in your source file (when using emacs). /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*- */ Then, after you inserted this, you return to the top of the file, press Ctrl-space, go to the bottom of the file and type Esc-x indent-region. Your source code file is now indented correctly according to GROMACS standards. It may be necessary to close and re-open the file, since emacs reads this magic comment only upon file opening. Block StructureIn order to make the source code readable always use braces around blocks, and put braces on the next line, even if it is unambiguous. Use if (foo)
{
blah();
}
else
{
bleh();
}
for (i=0; (i<imax); i++)
{
printf("Foo %d\n",i);
}
rather than: if (foo)
blah();
else
bleh();
for(i=0;i<imax;i++)
printf("Foo %d\n",i)
Note that there is an empty line between the two logical blocks ( Try to add a comment before a loop or conditional statement to tell *why* you are doing something, not what you are doing. Most users hacking the code know that Spaces are good - that's what the space-bar on your keyboard is so large :-) Personally I feel that e.g. using parentheses around the |