Difference between revisions of "Team Mighty Morphin Coding Rangers - OOP344"
(→Coding Style - updated the coding style (by DO)) |
m (→Coding Style - changes spacing from 2 to 4, added empty line after variable declaration) |
||
Line 27: | Line 27: | ||
<li>Class names must begin with a capital letter</li> | <li>Class names must begin with a capital letter</li> | ||
− | <li>Tab/space | + | <li>Tab/space four (4) spaces for every block of code. For example: </li> |
<code> | <code> | ||
− | main () { <br/> | + | main () { <br/><br/> |
− | + | int x, 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"); | |
− | + | } <br/><br/> | |
− | + | printf("Hello, world!"); <br/> | |
} <br/> | } <br/> | ||
</code> | </code> | ||
− | <li>Only <code>main ()</code> will start at column 1. Tab every block of 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. | <li>When using operators, make sure to have a space between the operands and the operator for readability. |
Revision as of 12:41, 24 January 2010
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:
- Comment as much as you can using /* ... */.
- At the top of every file, include your name, the filename, and the purpose of the file.
- Comment on what a function is supposed to do before the function definition.
- Change to newline once you reach column 80. Nothing to be typed beyond column 80!
- When naming variables,
- use single letters (like i, j, a, or v) for counters only;
- assign the variable a name that best describes what it is used for (but please don't make it too long);
- and separate words with caps.
Eg. noOfOrders, not nooforders
- When naming a function, name it according to what it is supposed to do.
Eg.void updateDelivery, int setInitialValue
, notvoid Deliveries, int InitialValues
- Class names must begin with a capital letter
- Tab/space four (4) spaces for every block of code. For example:
main () {
int x, y;
for (x = 0, y = 10; x < 10 && y > 0; x++, y++) {
printf("x is %d, y is %d\n", x, y);
printf("The sum of x and y is %d\n", x + y);
if (x == 5)
printf("We've reached the halfway point!\n"); }
printf("Hello, world!");
}
main ()
will start at column 1. Tab every block of code four spaces over.Eg.
i = 0;
, not i=0;
while, for, if, else,
put a space after the keyword and the expression following it.
Eg.
if (x == 0)
is correct; if(x == 0)
is incorrectEg. CORRECT:
int setSafeEmptyState {
...
}
INCORRECT:
int setSafeEmptyState
{
...
}