Open main menu

Difference between revisions of "Code Formatting Conventions"

substitute tabs with 4 spaces for visual consitency
m (update formatting to match original website's style)
(substitute tabs with 4 spaces for visual consitency)
Line 4: Line 4:


As such we don't follow these rules slavishly, in certain cases it is OK (and in fact favorable) to stray from them.
As such we don't follow these rules slavishly, in certain cases it is OK (and in fact favorable) to stray from them.
In the following examples tabs are replaced by spaces for visual consistency with the Code Formatting Conventions.


== 2. Hugging braces ==
== 2. Hugging braces ==
Line 10: Line 12:


<pre>
<pre>
if (int i = 0; i < t; i++) {
if (int i = 0; i < t; i++) {
[...]
    [...]
} else {
} else {
[...]
    [...]
}
}


class Dummy() {
class Dummy() {
[...]
    [...]
}
}
</pre>
</pre>


Line 32: Line 34:


<pre>
<pre>
a = (b + c) * d;
a = (b + c) * d;
</pre>
</pre>


Line 38: Line 40:


<pre>
<pre>
while (true) {
while (true) {
</pre>
</pre>


Line 44: Line 46:


<pre>
<pre>
someFunction(a, b, c);
someFunction(a, b, c);
int d, e;
int d, e;
</pre>
</pre>


Line 51: Line 53:


<pre>
<pre>
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
</pre>
</pre>


Line 58: Line 60:


<pre>
<pre>
class BusWheel : public RubberInflatable {
class BusWheel : public RubberInflatable {
(isNight) ? colorMeDark() : colorMeBright();
(isNight) ? colorMeDark() : colorMeBright();
</pre>
</pre>


Line 65: Line 67:


<pre>
<pre>
namespace Scumm {
namespace Scumm {


byte Actor::kInvalidBox = 0;
byte Actor::kInvalidBox = 0;


void Actor::initActorClass(ScummEngine *scumm) {
void Actor::initActorClass(ScummEngine *scumm) {
_vm = scumm;
    _vm = scumm;
}
}


} // End of namespace Scumm
} // End of namespace Scumm
</pre>
</pre>


Line 79: Line 81:


<pre>
<pre>
switch (cmd) {
switch (cmd) {
case kSaveCmd:
case kSaveCmd:
save();
    save();
break;
    break;
case kLoadCmd:
case kLoadCmd:
case kPlayCmd:
case kPlayCmd:
close();
    close();
break;
    break;
default:
default:
Dialog::handleCommand(sender, cmd, data);
    Dialog::handleCommand(sender, cmd, data);
}
}
</pre>
</pre>


Line 99: Line 101:


<pre>
<pre>
kSomeKludgyConstantName // notice k prefix
kSomeKludgyConstantName // notice k prefix
</pre>
</pre>


Line 105: Line 107:


<pre>
<pre>
SOME_KLUDGY_CONSTANT_NAME
SOME_KLUDGY_CONSTANT_NAME
</pre>
</pre>


Line 113: Line 115:


<pre>
<pre>
class MeClass() {
class MeClass() {
</pre>
</pre>


Line 121: Line 123:


<pre>
<pre>
char *_someVariableName;
char *_someVariableName;
</pre>
</pre>


Line 129: Line 131:


<pre>
<pre>
void thisIsMyFancyMethod();
void thisIsMyFancyMethod();
</pre>
</pre>