This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
styleguide [2020/04/13 17:24] rharris [Functions - Arguments] |
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]] | + | 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 8: | 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. Do not 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. | ||
Line 91: | 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 ===== |