Minimal Coding Conventions
Just about everyone in the VRL ends up re-using code and programs that someone else wrote previously, and undoubtedly the code that they write will be used by someone else in the future. Therefore the golden rule applies well to software development in our lab: do unto others as you would have them do unto you. This page records best practices for getting started developing software in an environment where code lives on through many generations of researchers.
The primary things to keep in mind are that:
- Future users of your code need read and write permission; and
- Future users of your code can't read your mind, so it must be organized and well-documented.
Minimal Coding Conventions
- Tabs are only meaningful in your edit session.
Do not use tabs (except in Makefiles as needed). Indent 4 spaces, but 3 is okay if you prefer.
- Name script files with suffixes.
Use Python for scripts (very portable). Avoid reliance on Cygwin.
- Commenting code does not slow progress.
If you make it a habit it speeds things up. At a minimum write a method’s purpose and parameter usage.
- Linux file system links are not portable. Never use them.
Coding in C++
- Use .cpp and .h suffixes for c++ source file names. Not: .C and .H
- Avoid conditional compilation (#ifdef).
- Use brackets around code bodies over multiple lines.
Evil: if (condition)
action;
Good: if (condition) action; if (condition) { action };
if (condition) if (condition)
{ action; {
} action;
}
- Line up brackets so they are easier to match visually.
- Do not #include .cpp files.