1
edit
Changes
→Programming Style
== Announcements ==
== Programming Style ==
=== Automated Formatting ===
The majority of formatting rules can be applied automatically using the [http://astyle.sourceforge.net/ astyle] software.
<code>astyle --style=kr --convert-tabs --pad-header --pad-oper --add-brackets --brackets=linux --lineend=linux file.cpp</code>
=== Indentation===
* Indents made with tabsspaces* Tab Indent size is four characters === Braces ===Braces should be made to match the K&R standard. This means that opening braces start on the same line as the expression that precedes them in all cases except for functions, and means that braces starting blocks should be one space away from the expression that precedes it. Functions will have their opening brace on the line after the declaration, and this brace will be the only character on the line. Closing braces for all blocks should similarly sit alone on the ending line of the scope, except for related expressions like 'else'. Bracing single-line blocks where it's not strictly necessary is strongly encouraged. === Parentheses ===Parentheses should be one space away from keywords such as 'if' and 'for', but should not be spaced when calling functions or operators. Essentially parentheses should be separate when they contain a condition, but attached when they contain an argument list. === Operators ===Binary operators should be spaced away from their operands, while unary operators should not. ===Classes = Blocks ==Classes must explicitly state the 'private:' tag for consistency even though not technically necessary. The private/protected/public order is preferred. These tags should not be indented relative to the class keyword. === Variable Naming ===lowerCamelCase names should be used such as:
<syntaxhighlight lang="cpp">
curPossetPosrowcol</syntaxhighlight> === Demonstration ===<syntaxhighlight lang="cpp">class Console {private: int _data;protected: public: Console(); ~Console();} int foo() { // That brace should be on the next line return sizeof (int); // This should be sizeof(int)} int bar(){ if ( foo() ) { // This brace should be one space away from the if's condition... return 3; }else if ( bar() ){ // ...and so should these braces return 2; } else { // This is right return 1; }} int main(){ char ch someChar = '0';
int i;
// Although K&R allows for this... for(i=0; i<10; i++){
cout << i;
// ...please do this instead
if ( foo() ) {
bar();
} else {
someChar = 'a';
}
switch(chsomeChar) {// switch is a keyword, so it should be switch (someChar) case '0':
cout << 0;
break;
case 1'a':
cout << 1;
break;
}
someChar+4; // Should be someChar + 4
! i; // Should be !i
return 0;
}</syntaxhighlight>
== Team Members ==