FlexSEA Wiki

A WEARABLE ROBOTICS TOOLKIT

User Tools

Site Tools


styleguide

Dephy C/C++ Programming Style Guide

General:

  • Use tabulations, not spaces. If you have to specify the tab size, use 4.
  • All files need to end with an empty line.
  • Do not use /* */ for comments that are on a single line, use //
  • As a general rule, make sure that your code looks clean and similar to the existing code (when existing code is provided)
  • Always include a comment above a function declaration that explains its purpose.
  • Always mention in what file extern variables are declared.
  • When you use a preprocessor statement such as #ifdef DEF_X, always add a closing comment such as #endif //DEF_X
  • Use the keyword 'ToDo' to flag stuff that should be fixed.
  • Variable names should start with a lower case. Use upper case to separate words. Good: int myNewVariable = 0; Bad: int MyNewVariable = 0; or int my_new_variable = 0;
  • All definitions and enumerated types should be in uppercase characters. Good: #define MY_CONSTANT 1, bad: #define myConstant 1

Functions:

USE:

//Description of the function
void my_function(void)
{
     //My Code
}

DO NOT USE:

void my_function(void){
//My Code
}

Always use the keyword 'void' when you do not have an argument. (USE void my_fct(void), DO NOT USE void my_fct())

Conditional statements:

Always use brackets, even if you have a single line below the statement. Do not put a space before the parentheses. Example:

USE:

if(value1 == value2)
{
     value3 = 1;
}

OR USE:

if(value1 == value2) { value3 = 1; }

DO NOT USE:

if(value1 == value2)
     value3 = 1;

Do not include a space between if and (). Good:

if(value1 == value2)

Bad:

if (value1 == value2)
styleguide.txt · Last modified: 2019/02/15 16:40 by jfduval