Changes

Jump to: navigation, search

Team Mighty Morphin Coding Rangers - OOP344

207 bytes removed, 13:30, 28 January 2010
Coding Style
__TOC__
 
 
== SVN Repository ==
 
<big>
oop344_101rep4
</big>
== Coding Style ==
The Coding Rangers had their first somewhat informal meeting on Jan. 21 to determine a uniform coding style. They came up with the following:
<ul>
<li>Comment as much as you can using /* ... */. </li> <ul> <li>At the top of every file, include your name, the filename, and the purpose of the file.</li>
<li>Comment on what a function is supposed to do before the function definition.</li> </ul>
<li>Change to newline once you reach <b>column 80</b>. Nothing to be typed beyond column 80!</li> <li>When naming variables, <ul><li>use single letters (like i, j, a, or v) for counters only; </li><li>assign the variable a name that best describes what it is used for (but please don't make it too long);</li><li>and separate words with caps.
<li>When naming variables,
<ul>
<li>use single letters (like i, j, a, or v) for counters only; </li>
<li>assign the variable a name that best describes what it is used for (but please don't make it too long);</li>
<li>and separate words with caps.
<br/> Eg. no<b>O</b>f<b>O</b>rders, not no<b>o</b>f<b>o</b>rders
</ul> </li> <li>When naming a function, name it according to what it is supposed to do.
<li>When naming a function, name it according to what it is supposed to do.
<br />Eg. <code>void updateDelivery, int setInitialValue</code>, not <code>void Deliveries, int InitialValues</code></li>
<li>Class names must begin with a capital letter</li>
<li>Declare each variable in a line by itself. It is easier to comment a variable this way. Do not use commas to separate the variable names if they have the same data type.</li>
<code>
Eg. correct int i; //To count the number of times in for-loop int j; int k; //To count another variable Eg. wrong int i,j,k; //How do I separately comment int i; int j; int k; //the variables here?
</code>
<li>Type four (4) spaces over for every block of code. (This is as opposed to tabbing.) For example: </li>
<code>
main () { <br/><br/> int x; //Notice the four spaces over <br/> int y; <br/><br/> for (x = 0, y = 10; x < 10 && y > 0; x++, y++) { <br/> printf("x is %d, y is %d\n", x, y); <br/> printf("The sum of x and y is %d\n", x + y); <br/> if (x == 5) <br/> printf("We've reached the halfway point!\n"); //Moved four spaces over } <br/><br/> printf("Hello, world!"); <br/> } <br/>
</code>
<li>Only <code>main ()</code> will start at column 1. Tab every block of code four spaces over.</li> <li>Include an empty line after the declaration of variables (see above example).</li> <li>When using operators, make sure to have a space between the operands and the operator for readability.
<libr/>Include an empty line after the declaration of variables (see above example)Eg.<code>i = 0;</code>, not <code>i=0;</code></li>
<li>When using operators, make sure to have a space between the operands and the operator for readability. <br/>Eg. For keywords such as <code>i = 0;</code>while, for, if, else, not <code>i=0;</code></li>put a space after the keyword and the expression following it.
<li>For keywords such as <code>while, for, if, else, </code> put a space after the keyword and the expression following it. <br/> Eg. <code>if (x == 0)</code> is correct; <code>if(x == 0)</code> is incorrect</li>
<li>When using brackets, put the opening bracket on the same line as the function or expression that opens it. <br/> Eg. <b>CORRECT: </b> <br/> <code>int setSafeEmptyState { <br/> ... <br/> } </code> <br/> <b>INCORRECT: </b> <br/> <code>int setSafeEmptyState <br/> { <br/> ... <br/> } </code> <br/> </li>
</ul>

Navigation menu