Hopsan
|
The following coding style is the preferred in all Hopsan C++ code.
Example:
Note! The previous (deprecated) style is still used in most of the code. The previous style said that "There shall be one line break before all brackets." This style can still be used if it makes the code easier to read.
Example:
Exceptions can be made for short one-line code blocks, but are generally not recommended.
Example:
All code shall be self commenting. This means that non-obvious abbreviations shall be avoided. The purpose of a variable shall be well described by its name. Exceptions are component equations, where the physical denotation of the variable is to be used.
Correct:
Incorrect:
Variables begin with small letters, while every new word in the name shall be capitalized.
Correct:
Incorrect:
Certain variables shall have one or more small description letters prepended:
Optional:
More than one letter can be used at a time. When these letters are prepended, the first letter in the actual variable name shall be capitalized.
Examples:
All global variables, member variables, pointers and number variables should have these prepended letters. An exception is made for public variables used in a data struct (public class) when its main purpose is to act as a simple data container.
Example: