Hacking:Code style conventions

General
Max length of source code line equal 120 characters. Put "//---" cars in front of function definitions with maximum length (120) :

Don't use

C++ namespaces and the using namespace  statement can confuse lupdate. It will interpret  like. Runtime translation of these strings will fail because of that.

Indentation
Use spaces, not tabs. 4 spaces instead one real tab. Tabs should only appear in files that require them for semantic meaning, like Makefiles.

A case label should be indented with its switch statement. The case statement is indented too.

Spacing
Do not place spaces around unary operators.

Do place spaces around binary and ternary operators.

Do not place spaces before comma and semicolon.

Place spaces between control statements and their parentheses.

Do not place spaces between a function and its parentheses, or between a parenthesis and its content.

Line breaking
Each statement should get its own line.

Braces
Use typically trailing braces everywhere (if, else, functions, structures, typedefs, class definitions, etc.)

The else statement starts on new line after the last closing brace.

Null and false
In C++, the null pointer value should be written as. In C, it should be written as.

Negation operator should not be used in its short form :

Floating point literals
Unless required in order to force floating point math, do not append,   and   to floating point literals.

Names
Function names start with an upper case:

In multi-word function names each word starts with an upper case, including all letters in an acronym:

Variable names start with a lower case character.

In multi-word variable names the first word starts with a lower case character and each successive word starts with an upper case.

Names of recursive functions end with "_r"

Defined names use all upper case characters. Multiple words are separated with an underscore.

Use full words, except in the rare case where an abbreviation would be more canonical and easier to understand.

Data members in C++ classes should be private. Static data members should be prefixed by “s_”. Other data members should be prefixed by “m_”.

Use ‘const’ as much as possible. Use:

Same true for variables that will not be changed after initialization.

Don’t use:

Precede boolean values with words like “is” and “did”.

Precede getters that return values through out arguments with the word “get”.

Use descriptive verbs in function names.

Prefer  to. Prefer inline functions to macros.

Macros that expand to function calls or other non-constant computation: these should be named like functions, and should have parentheses at the end, even if they take no arguments (with the exception of some special macros like ASSERT). Note that usually it is preferable to use an inline function in such cases instead of a macro.

,  “header guards” should be named exactly the same as the file (including case), replacing the   with a.

For suppressing compiler warnings about unused parameters in code use  macros.

Other Punctuation
Constructors for C++ classes should initialize all of their members using C++ initializer syntax. Each member (and superclass) should be indented on a separate line, with the colon or comma preceding the member on that line.

Prefer index over iterator in Vector iterations for terse, easier-to-read code. Right: OK:

Classes
Class names start with "V" and each successive word starts with an upper case.

Class variables have the same naming convention as variables.

Class methods have the same naming convention as functions.

Indent the names of class variables and class methods to make nice columns. The variable type or method return type is in the first column and the variable name or method name is in the second column.

The * of the pointer is in the first column because it improves readability when considered part of the type.

Ordering of class variables and methods should be as follows:
 * 1) list of friend classes
 * 2) public variables
 * 3) public methods
 * 4) protected variables
 * 5) protected methods
 * 6) private variables
 * 7) private methods

This allows the public interface to be easily found at the beginning of the class.

Always make class methods ‘const’ when they do not modify any class variables.

Avoid use of ‘const_cast’. When object is needed to be modified, but only const versions are accessible, create a function that clearly gives an editable version of the object. This keeps the control of the ‘const-ness’ in the hands of the object and not the user.

Function overloading should be avoided in most cases. For example, instead of:

Use:

Inline member functions define outside the class:

Note. Don't make virtual methods inline. See Clang warning -Wweak-vtables. Discusion on StackOverflow.

File names
Each class should be in a separate source file unless it makes sense to group several smaller classes. The file name should be the same as the name of the class with the "V" prefix.

files: