FlexSEA Wiki

A WEARABLE ROBOTICS TOOLKIT

User Tools

Site Tools


styleguide

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
styleguide [2019/02/15 16:40]
jfduval
styleguide [2019/09/11 19:07] (current)
jfduval
Line 7: Line 7:
   * Do not use ''/​* */''​ for comments that are on a single line, use <​nowiki>​ // </​nowiki>​   * Do not use ''/​* */''​ for comments that are on a single line, use <​nowiki>​ // </​nowiki>​
   * As a general rule, make sure that your code looks clean and similar to the existing code (when existing code is provided)   * As a general rule, make sure that your code looks clean and similar to the existing code (when existing code is provided)
 +  * In your comments, start sentences with capital letters. Do not put a space between the <​nowiki>//</​nowiki>​ and the text.
 +    * Good: <color #​22b14c><​nowiki>//​That'​s a good comment</​nowiki></​color>​
 +    * Bad: <color #​ed1c24><​nowiki>//​ this isn'​t</​nowiki></​color>​
   * Always include a comment above a function declaration that explains its purpose.   * Always include a comment above a function declaration that explains its purpose.
   * Always mention in what file extern variables are declared.   * Always mention in what file extern variables are declared.
   * When you use a preprocessor statement such as <​nowiki>#​ifdef DEF_X</​nowiki>,​ always add a closing comment such as <​nowiki>#​endif //​DEF_X</​nowiki>​   * When you use a preprocessor statement such as <​nowiki>#​ifdef DEF_X</​nowiki>,​ always add a closing comment such as <​nowiki>#​endif //​DEF_X</​nowiki>​
   * Use the keyword '​ToDo'​ to flag stuff that should be fixed.   * 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: <color #​22b14c>​int myNewVariable = 0;</​color>​ Bad: <color #​ed1c24>​int MyNewVariable = 0;</​color> ​or <color #​ed1c24>​int my_new_variable = 0;</​color>​ +  * Variable names should start with a lower case. Use upper case to separate words. ​ 
-  * All definitions and enumerated types should be in uppercase characters. Good: <color #​22b14c>#​define MY_CONSTANT 1</​color>​, bad: <color #​ed1c24>#​define myConstant 1</​color>​+    * Good: <color #​22b14c>​int myNewVariable = 0;</​color>​ 
 +    * Bad: <color #​ed1c24>​int MyNewVariable = 0;</​color>​ 
 +    * Bad: <color #​ed1c24>​int my_new_variable = 0;</​color>​ 
 +  * All definitions and enumerated types should be in uppercase characters. ​ 
 +    * Good: <color #​22b14c>#​define MY_CONSTANT 1</​color>​ 
 +    * Bad: <color #​ed1c24>#​define myConstant 1</​color>​ 
 +  * On empty lines: 
 +    * Use one to separate different blocks of code 
 +    * Do not use more than one at a time 
 +    * Main objective: code readability 
 +  * When in doubt, add more parentheses than needed. It usually makes the code easier to read, and it removes doubts about operator priority.
  
-__**Functions:​**__+__**Functions ​- Brackets:**__
  
-USE:+<color #​22b14c>​Good:</​color>​
  
 <​code>​ <​code>​
Line 26: Line 39:
 </​code>​ </​code>​
  
-DO NOT USE:+<color #​ed1c24>​Bad:</​color>​
  
 <​code>​void my_function(void){ <​code>​void my_function(void){
Line 32: Line 45:
 }</​code>​ }</​code>​
  
-Always use the keyword '​void'​ when you do not have an argument. (USE <color #​22b14c>​void my_fct(void)</​color>,​ DO NOT USE <color #​ed1c24>​void my_fct()</​color>​)+__**Functions - Arguments:​**__
  
-__**Conditional statements:​**__+Always use the keyword '​void'​ when you do not have an argument. 
 + 
 +<color #​22b14c>​Good:</​color>​ 
 + 
 +<​code>​void my_fct(void)</​code>​ 
 + 
 +<color #​ed1c24>​Bad:</​color>​ 
 + 
 +<​code>​void my_fct()</​code>​ 
 + 
 +__**Loops and Conditional statements ​- Brackets:**__
  
 Always use brackets, even if you have a single line below the statement. Do not put a space before the parentheses. Example: Always use brackets, even if you have a single line below the statement. Do not put a space before the parentheses. Example:
  
-USE:+<color #​22b14c>​Good:</​color>​
  
 <​code>​if(value1 == value2) <​code>​if(value1 == value2)
Line 45: Line 68:
 }</​code>​ }</​code>​
  
-OR USE:+<color #​22b14c>​Also good:</​color>​
  
-<​code>​if(value1 == value2) { value3 = 1; }</​code>​+<​code>​if(value1 == value2){ value3 = 1; }</​code>​
  
- +<color #​ed1c24>​Bad:</​color>​
-DO NOT USE:+
  
 <​code>​if(value1 == value2) <​code>​if(value1 == value2)
      ​value3 = 1;</​code>​      ​value3 = 1;</​code>​
-      + 
-Do not include a space between if and (). Good:+__**Conditional statements - Spaces:​**__ 
 + 
 +Do not include a space between if and ().  
 + 
 +<color #22b14c>Good:</​color>​
  
 <​code>​if(value1 == value2)</​code>​ <​code>​if(value1 == value2)</​code>​
  
-Bad:+<color #ed1c24>Bad:</​color>​
  
 <​code>​if (value1 == value2)</​code>​ <​code>​if (value1 == value2)</​code>​
 +
 +__**Operators and spaces**__
 +
 +<color #​22b14c>​Good:</​color>​
 +
 +<​code>​myVar = (i * 20) / (a + 1)</​code>​
 +
 +<color #​ed1c24>​Bad:</​color>​
 +
 +<​code>​myVar = (i*20)/​(a+1)</​code>​
styleguide.1550248801.txt.gz · Last modified: 2019/02/15 16:40 by jfduval