Difference between revisions of "Coding style"

From Medusa: Coordinate Free Mehless Method implementation
Jump to: navigation, search
(Comments)
Line 61: Line 61:
  
 
Use doxygen comments to generate [[documentation]].
 
Use doxygen comments to generate [[documentation]].
 +
 +
<syntaxhighlight lang="python" line>
 +
def quickSort(arr):
 +
less = []
 +
pivotList = []
 +
more = []
 +
if len(arr) <= 1:
 +
return arr
 +
else:
 +
pass
 +
</syntaxhighlight>
  
 
=Headers =
 
=Headers =

Revision as of 17:42, 7 November 2016

This is a brief description of our coding style, roughtly following the Google C++ Style Guide.

General

A soft $80$ characters line width limit.

Indentation

Indent using spaces. Indentation width is $4$ spaces.

1 for (int i = 0; i < 10; i++) {
2     cout << i << endl;
3 }

Naming convention

Constants - UPPER_CASE

classes - PascalCase

methods - camelCase

variables and stand-alone functions - underscore_separated

typedefs - lowercase underscore separated, usually one word with trailing _t, eg. vec_t.

namespaces - one lowercase word, maybe shortened, eg. op. For internal implementation details use op_internal. Namespace closing brace should contain comment // namespace your_name. There is no indentation within namespaces.

All standard abbreviations like Moving Least Squres (MLS) or Finite Elements Method (FEM) - UPPER_CASE

Floating point and integer literals use small suffixes, eg. 0.0f, -1e8l, 45ull .

1 #define MAX_VALUE 500
2 class MyClass {
3   public:
4     MyClass(first_var, second_var) {
5         ...
6     }
7     int getSize();
8 }

Comments

Comments are good. Use them to explain your code. Comments should have a space between the last slash and the start of text. Inline comments should have at least two spaces between end of code and start of the comment.

1 // This function will change the world
2 double change_the_world(bool skynet) {
3     if (skynet) {
4         return 0.0;  // Brace for the end of the world
5     }
6     ...
7 }

Use doxygen comments to generate documentation.

1 def quickSort(arr):
2 	less = []
3 	pivotList = []
4 	more = []
5 	if len(arr) <= 1:
6 		return arr
7 	else:
8 		pass

Headers

All headers must contain a header guard of form PARTH_TO_FILENAME_HPP_ as enforced by the linter.

Includes in header guards are separated in two groups, with intra-project includes on top and other includes on the bottom. The groups are separated by a blank line and includes are kept sorted within a group.

Misc

Avoid trailing whitespace. Curly opening brackets { should be inline with for loops, function definitions, class names, separated with a space. Outermost binary operators should have spaces around them.

1 int sumMe(int var) {  // yes
2     if (var == 1)
3     {                 // no
4         return 1;
5     }
6     return 0;
7 }

For null pointer we use nullptr instead of NULL macro.