1,554
edits
(Use syntax highligher) |
|||
Line 11: | Line 11: | ||
Braces in your code should look like the following example: | Braces in your code should look like the following example: | ||
< | <syntax type="C++"> | ||
for (int i = 0; i < t; i++) { | for (int i = 0; i < t; i++) { | ||
[...] | [...] | ||
Line 25: | Line 25: | ||
[...] | [...] | ||
}; | }; | ||
</ | </syntax> | ||
Did you see the {}'s on that? | Did you see the {}'s on that? | ||
Line 37: | Line 37: | ||
'''Conventional operators surrounded by a space character''' | '''Conventional operators surrounded by a space character''' | ||
< | <syntax type="C++"> | ||
a = (b + c) * d; | a = (b + c) * d; | ||
</ | </syntax> | ||
'''C++ reserved words separated from opening parentheses by a white space''' | '''C++ reserved words separated from opening parentheses by a white space''' | ||
< | <syntax type="C++"> | ||
while (true) { | while (true) { | ||
</ | </syntax> | ||
'''Commas followed by a white space''' | '''Commas followed by a white space''' | ||
< | <syntax type="C++"> | ||
someFunction(a, b, c); | someFunction(a, b, c); | ||
int d, e; | int d, e; | ||
</ | </syntax> | ||
'''Semicolons followed by a space character, if there is more on line''' | '''Semicolons followed by a space character, if there is more on line''' | ||
< | <syntax type="C++"> | ||
for (int a = 0; b++; c < d) | for (int a = 0; b++; c < d) | ||
doSomething(e); doSomething(f); // This is probably bad style anyway | doSomething(e); doSomething(f); // This is probably bad style anyway | ||
</ | </syntax> | ||
'''When declaring class inheritance and in a ? construct, colons should be surrounded by white space''' | '''When declaring class inheritance and in a ? construct, colons should be surrounded by white space''' | ||
< | <syntax type="C++"> | ||
class BusWheel : public RubberInflatable { | class BusWheel : public RubberInflatable { | ||
(isNight) ? colorMeDark() : colorMeBright(); | (isNight) ? colorMeDark() : colorMeBright(); | ||
</ | </syntax> | ||
'''Indentation level is not increased after namespace clause''' | '''Indentation level is not increased after namespace clause''' | ||
< | <syntax type="C++"> | ||
namespace Scumm { | namespace Scumm { | ||
Line 80: | Line 80: | ||
} // End of namespace Scumm | } // End of namespace Scumm | ||
</ | </syntax> | ||
'''Array delete operator has no whitespace before []''' | '''Array delete operator has no whitespace before []''' | ||
< | <syntax type="C++"> | ||
delete[] foo; | delete[] foo; | ||
</ | </syntax> | ||
'''Template definitions''' | '''Template definitions''' | ||
No whitespace between template keyword and < | No whitespace between template keyword and < | ||
< | <syntax type="C++"> | ||
template<typename foo> | template<typename foo> | ||
void myFunc(foo arg) { | void myFunc(foo arg) { | ||
// ... | // ... | ||
} | } | ||
</ | </syntax> | ||
'''Operator overloading''' | '''Operator overloading''' | ||
Operator keyword is NOT separated from the name, except for type conversion operators where it is required. | Operator keyword is NOT separated from the name, except for type conversion operators where it is required. | ||
< | <syntax type="C++"> | ||
struct Foo { | struct Foo { | ||
void operator()() { | void operator()() { | ||
Line 110: | Line 110: | ||
} | } | ||
}; | }; | ||
</ | </syntax> | ||
'''Pointers and casts''' | '''Pointers and casts''' | ||
No whitespace after a cast; and in a pointer, we write a whitespace before the start but not after it. | No whitespace after a cast; and in a pointer, we write a whitespace before the start but not after it. | ||
< | <syntax type="C++"> | ||
const char *ptr = (const char *)foobar; | const char *ptr = (const char *)foobar; | ||
</ | </syntax> | ||
== Switch / Case constructs == | == Switch / Case constructs == | ||
< | <syntax type="C++"> | ||
switch (cmd) { | switch (cmd) { | ||
case kSaveCmd: | case kSaveCmd: | ||
Line 133: | Line 133: | ||
Dialog::handleCommand(sender, cmd, data); | Dialog::handleCommand(sender, cmd, data); | ||
} | } | ||
</ | </syntax> | ||
== Naming == | == Naming == | ||
Line 150: | Line 150: | ||
Camel case starting with upper case. | Camel case starting with upper case. | ||
< | <syntax type="C++"> | ||
class MeClass() { | class MeClass() { | ||
</ | </syntax> | ||
'''Class member variables''' | '''Class member variables''' | ||
Line 158: | Line 158: | ||
Prefixed with '_' and in camel case (Yo! no underscore separators), starting with lowercase. | Prefixed with '_' and in camel case (Yo! no underscore separators), starting with lowercase. | ||
< | <syntax type="C++"> | ||
char *_someVariableName; | char *_someVariableName; | ||
</ | </syntax> | ||
'''Class methods''' | '''Class methods''' | ||
Line 166: | Line 166: | ||
Camel case, starting with lowercase. | Camel case, starting with lowercase. | ||
< | <syntax type="C++"> | ||
void thisIsMyFancyMethod(); | void thisIsMyFancyMethod(); | ||
</ | </syntax> | ||
'''Global variables''' | '''Global variables''' | ||
Line 174: | Line 174: | ||
In general you should avoid global variables, but if it can't be avoided, use 'g_' as prefix, camel case, and start with lowercase | In general you should avoid global variables, but if it can't be avoided, use 'g_' as prefix, camel case, and start with lowercase | ||
< | <syntax type="C++"> | ||
int g_someGlobaleVariable; | int g_someGlobaleVariable; | ||
</ | </syntax> | ||
== Special comments == | == Special comments == | ||
Line 195: | Line 195: | ||
There are many ways to mark such comments, but developers are encouraged to use the JavaDoc style: | There are many ways to mark such comments, but developers are encouraged to use the JavaDoc style: | ||
< | <syntax type="C++"> | ||
/** | /** | ||
* Move ("warp") the mouse cursor to the specified position in virtual | * Move ("warp") the mouse cursor to the specified position in virtual | ||
Line 203: | Line 203: | ||
*/ | */ | ||
virtual void warpMouse(int x, int y) = 0; | virtual void warpMouse(int x, int y) = 0; | ||
</ | </syntax> | ||
(See [http://doxygen.scummvm.org/d9/df4/classOSystem.html#ecab84670def917107d6c1b5ca3b82c3 here] for the docs generated from this.) | (See [http://doxygen.scummvm.org/d9/df4/classOSystem.html#ecab84670def917107d6c1b5ca3b82c3 here] for the docs generated from this.) | ||
Line 209: | Line 209: | ||
If you want to add a brief explanation of a variable or function ''after'' its declaration, this is the correct syntax: | If you want to add a brief explanation of a variable or function ''after'' its declaration, this is the correct syntax: | ||
< | <syntax type="C++"> | ||
int16 x; //!< The horizontal part of the point | int16 x; //!< The horizontal part of the point | ||
int16 y; //!< The vertical part of the point | int16 y; //!< The vertical part of the point | ||
</ | </syntax> | ||
(See [http://doxygen.scummvm.org/d7/d66/structCommon_1_1Point.html#2d868735aeaaf391ce9b3df9232c031f here] for the docs generated from this.) | (See [http://doxygen.scummvm.org/d7/d66/structCommon_1_1Point.html#2d868735aeaaf391ce9b3df9232c031f here] for the docs generated from this.) | ||