Open main menu

Difference between revisions of "Code Formatting Conventions"

m
update formatting
(inital Wiki Code_formatting_Conventions)
 
m (update formatting)
Line 1: Line 1:
1. Use common sense
 
== 1. Use common sense ==
 
These are conventions which we try to follow when writing code for ScummVM. They are this way mainly for reasons of taste, however, sticking to a common set of formatting rules also makes it slightly easier to read through our sources. If you want to submit patches, please try to follow these rules.  
These are conventions which we try to follow when writing code for ScummVM. They are this way mainly for reasons of taste, however, sticking to a common set of formatting rules also makes it slightly easier to read through our sources. If you want to submit patches, please try to follow these rules.  


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.  


2. Hugging braces
== 2. Hugging braces ==
 
Braces in your code should look like the following example:
Braces in your code should look like the following example:


Line 19: Line 22:
Did you see the {}'s on that?
Did you see the {}'s on that?


3. Tab indents, with tabstop at four spaces
== 3. Tab indents, with tabstop at four spaces ==
 
Says it all, really.  
Says it all, really.  
4. Whitespaces
 
== 4. Whitespaces ==
 
Conventional operators surrounded by a space character
Conventional operators surrounded by a space character
a = (b + c) * d;
a = (b + c) * d;
Line 51: Line 57:
} // End of namespace Scumm
} // End of namespace Scumm


== 5. Switch / Case constructs ==
5. Switch / Case constructs
 
switch (cmd) {
switch (cmd) {
case kSaveCmd:
case kSaveCmd:
Line 64: Line 70:
Dialog::handleCommand(sender, cmd, data);
Dialog::handleCommand(sender, cmd, data);
}
}
 
6. Naming
== 6. Naming ==
 
Constants
Constants