Difference between revisions of "Code Formatting Conventions"

Jump to navigation Jump to search
→‎Switch/Case constructs: enhanced to avoid ambiguity
(→‎Vertical space: -- new section)
(→‎Switch/Case constructs: enhanced to avoid ambiguity)
 
(2 intermediate revisions by the same user not shown)
Line 167: Line 167:
switch (cmd) {
switch (cmd) {
case kSomeCmd:
case kSomeCmd:
     someCmd();
     a = 1;
    func1();
    b = a + 1;
     // fall through
     // fall through
case kSomeVerySimilarCmd:
case kSomeVerySimilarCmd:
     someMoreCmd();
     someMoreCmd();
    a = 3;
     break;
     break;
case kSaveCmd:
case kSaveCmd:
Line 184: Line 187:
</syntaxhighlight>
</syntaxhighlight>
* Note the comment on whether fall through is intentional. Use exactly this and not some variation both for consistency and so that the compiler will see it and suppress potential warnings.
* Note the comment on whether fall through is intentional. Use exactly this and not some variation both for consistency and so that the compiler will see it and suppress potential warnings.


== Vertical space ==
== Vertical space ==
Line 261: Line 263:
'''Type names'''
'''Type names'''


Camel case starting with upper case.
Camel case starting with upper case. This includes template types.


<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
Line 267: Line 269:
struct MyStruct { /* ... */ };
struct MyStruct { /* ... */ };
typedef int MyInt;
typedef int MyInt;
template typename<FancyPants>
void bestClothes(FancyPants pants) {/* ... */ }
</syntaxhighlight>
</syntaxhighlight>


Line 283: Line 288:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
void thisIsMyFancyMethod();
void thisIsMyFancyMethod();
</syntaxhighlight>
'''Non-member functions'''
Camel case, starting with lowercase.
<syntaxhighlight lang="cpp">
void thisIsMyFancyGlobalFunction();
</syntaxhighlight>
</syntaxhighlight>


Line 311: Line 324:
* '''TODO''' marks incomplete code, or things that could be done better but are left for the future.
* '''TODO''' marks incomplete code, or things that could be done better but are left for the future.
* '''WORKAROUND''' marks code that works around bugs in the original game, like script bugs. Sometimes these bugs worked in the original due to bugs in the original engine, sometimes the bug was visible in the original, too. It's important that you explain here what exactly you work around, and if applicable, refer to relevant tracker items!
* '''WORKAROUND''' marks code that works around bugs in the original game, like script bugs. Sometimes these bugs worked in the original due to bugs in the original engine, sometimes the bug was visible in the original, too. It's important that you explain here what exactly you work around, and if applicable, refer to relevant tracker items!
* '''I18N:''' Adds comment to translators for internationalization. See [[Supporting GUI Translation]].


=== Doxygen documentation comments ===
=== Doxygen documentation comments ===

Navigation menu