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/11/07 20:47]
jfduval
styleguide [2020/10/29 15:10] (current)
tmayadagli [Conditional compilation]
Line 1: Line 1:
 ====== Dephy C/C++ Programming Style Guide ====== ====== Dephy C/C++ Programming Style Guide ======
 +
 +Programming in Python? [[styleguidepython|Dephy Python Programming Style Guide]]. ​
 +
 +Looking for a way to review your code? A checklist for this style guide lives [[internal:​code_checklist|here.]]
  
 ===== General ===== ===== General =====
Line 6: Line 10:
   * Use <color #​22b14c>​tabulations</​color>,​ not <color #​ed1c24>​spaces</​color>​. If you have to specify the tab size, use 4.   * Use <color #​22b14c>​tabulations</​color>,​ not <color #​ed1c24>​spaces</​color>​. If you have to specify the tab size, use 4.
   * All files need to end with an empty line.   * All files need to end with an empty line.
-  * Do not use ''/​* */'' ​for comments that are on a single line, use <​nowiki>//</​nowiki>​+  * Do not use ''/​* */'' ​unless absolutely necessary, such as commenting out large chunks of code. Instead, 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). More examples below.   * As a general rule, make sure that your code looks clean and similar to the existing code (when existing code is provided). More examples below.
-  * In your comments, start sentences with capital letters. ​Put a space between the <​nowiki>//</​nowiki>​ and the text.+  * 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>​     * Good: <color #​22b14c><​nowiki>//​That'​s a good comment</​nowiki></​color>​
     * Bad: <color #​ed1c24><​nowiki>//​ this isn'​t</​nowiki></​color>​     * Bad: <color #​ed1c24><​nowiki>//​ this isn'​t</​nowiki></​color>​
Line 15: Line 19:
   * 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. ​+  * Function and variable ​names should start with a lower case. Use upper case to separate words. ​
     * Good: <color #​22b14c>​int myNewVariable = 0;</​color>​     * Good: <color #​22b14c>​int myNewVariable = 0;</​color>​
     * Bad: <color #​ed1c24>​int MyNewVariable = 0;</​color>​     * Bad: <color #​ed1c24>​int MyNewVariable = 0;</​color>​
Line 34: Line 38:
 <​code>​ <​code>​
 //​Description of the function //​Description of the function
-void my_function(void)+void myFunction(void)
 { {
      //My Code      //My Code
Line 42: Line 46:
 <color #​ed1c24>​Bad:</​color>​ <color #​ed1c24>​Bad:</​color>​
  
-<​code>​void ​my_function(void){+<​code>​void ​myFunction(void){
 //My Code //My Code
 }</​code>​ }</​code>​
Line 52: Line 56:
 <color #​22b14c>​Good:</​color>​ <color #​22b14c>​Good:</​color>​
  
-<​code>​void ​my_fct(void)</​code>​+<​code>​void ​myFct(void)</​code>​
  
 <color #​ed1c24>​Bad:</​color>​ <color #​ed1c24>​Bad:</​color>​
  
-<​code>​void ​my_fct()</​code>​+<​code>​void ​myFct()</​code>​
  
 ===== Loops and Conditional statements - Brackets =====  ===== Loops and Conditional statements - Brackets ===== 
Line 89: Line 93:
  
 <​code>​if (value1 == value2)</​code>​ <​code>​if (value1 == value2)</​code>​
 +
 +===== Conditional compilation =====
 +
 +<color #​22b14c>​Good:</​color>​
 +
 +<​code>​
 +#ifdef MACRO
 +     ​controlled text
 +#endif //MACRO
 +</​code>​
 +
 +<color #​ed1c24>​Bad:</​color>​
 +
 +<​code>​
 +#ifdef MACRO
 +controlled text
 +#endif
 +</​code>​
  
 ===== Operators and spaces ===== ===== Operators and spaces =====
styleguide.1573159623.txt.gz ยท Last modified: 2019/11/07 20:47 by jfduval