Changes

Jump to navigation Jump to search
m
Text replacement - "<source lang=" to "<syntaxhighlight lang="
Braces in your code should look like the following example:
<source syntaxhighlight lang="cpp">
for (int i = 0; i < t; i++) {
[...]
'''Conventional operators surrounded by a space character'''
<source syntaxhighlight lang="cpp">
a = (b + c) * d;
</syntaxhighlight>
'''C++ reserved words separated from opening parentheses by a white space'''
<source syntaxhighlight lang="cpp">
while (true) {
</syntaxhighlight>
'''Commas followed by a white space'''
<source syntaxhighlight lang="cpp">
someFunction(a, b, c);
</syntaxhighlight>
<source syntaxhighlight lang="cpp">
int d, e;
</syntaxhighlight>
'''Semicolons followed by a space character, if there is more on a line'''
<source syntaxhighlight lang="cpp">
for (int a = 0; b < c; d++)
</syntaxhighlight>
<source syntaxhighlight lang="cpp">
doSomething(e); doSomething(f); // This is probably bad style anyway
</syntaxhighlight>
'''Mandatory ''{}'' for empty ''for''/''while'' loops'''
<source syntaxhighlight lang="cpp">
while (i < length - 1 && array[++i] != item); // bad
while (i < length - 1 && array[++i] != item) {} // good
'''When declaring class inheritance and in a ? construct, colons should be surrounded by white space'''
<source syntaxhighlight lang="cpp">
class BusWheel : public RubberInflatable {
</syntaxhighlight>
<source syntaxhighlight lang="cpp">
(isNight) ? colorMeDark() : colorMeBright();
</syntaxhighlight>
'''Indentation level is not increased after namespace clause'''
<source syntaxhighlight lang="cpp">
namespace Scumm {
'''Array delete operator has no whitespace before []'''
<source syntaxhighlight lang="cpp">
delete[] foo;
</syntaxhighlight>
No whitespace between template keyword and <
<source syntaxhighlight lang="cpp">
template<typename foo>
void myFunc(foo arg) {
Operator keyword is NOT separated from the name, except for type conversion operators where it is required.
<source syntaxhighlight lang="cpp">
struct Foo {
void operator()() {
No whitespace after a cast; and in a pointer, we write a whitespace before the star but not after it.
<source syntaxhighlight lang="cpp">
const char *ptr = (const char *)foobar;
</syntaxhighlight>
We use the same rule for references as we do for pointers: use a whitespace before the "&" but not after it.
<source syntaxhighlight lang="cpp">
int i = 0;
int &ref = i;
When it adds to readability, a vertical alignment by means of extra tabs or spaces is allowed. However, it is not advised to have the opening and closing brackets/braces to occupy a single line.
<source syntaxhighlight lang="cpp">
int foo = 2;
int morefoo = 3;
== Switch/Case constructs ==
<source syntaxhighlight lang="cpp">
switch (cmd) {
case kSomeCmd:
Camel case starting with upper case.
<source syntaxhighlight lang="cpp">
class MyClass { /* ... */ };
struct MyStruct { /* ... */ };
Prefixed with '_' and in camel case (Yo! no underscore separators), starting with lowercase.
<source syntaxhighlight lang="cpp">
char *_someVariableName;
</syntaxhighlight>
Camel case, starting with lowercase.
<source syntaxhighlight lang="cpp">
void thisIsMyFancyMethod();
</syntaxhighlight>
Use camel case (Yo! no underscore separators), starting with lowercase.
<source syntaxhighlight lang="cpp">
char *someVariableName;
</syntaxhighlight>
In general you should avoid global variables, but if it can't be avoided, use 'g_' as prefix, camel case, and start with lowercase
<source syntaxhighlight lang="cpp">
int g_someGlobalVariable;
</syntaxhighlight>
There are many ways to mark such comments, but developers are encouraged to use the JavaDoc style:
<source syntaxhighlight lang="cpp">
/**
* Move ("warp") the mouse cursor to the specified position in virtual
If you want to add a brief explanation of a variable or function ''after'' its declaration, this is the correct syntax:
<source syntaxhighlight lang="cpp">
int16 x; ///< The horizontal part of the point
int16 y; ///< The vertical part of the point
TrustedUser
2,000

edits

Navigation menu