Changes

Jump to: navigation, search

OOP344 - HOTYS - 20102

2,416 bytes added, 18:39, 23 May 2010
Coding Style Rules: Final Version
==<big>Coding Style Rules</big>==
<pre>Every file should have a function header with:<br /><ul> <li>File name</li> <li>Programmer Full name</li> <li>Date last modified</li></ul>
Example:<br /><div><b style="color: #008800; line-height: 0.5em;"> /*<br /> Title<br /> Title.h<br /> By: Full Name<br /> Date Last Modified: 9:59 AM April-15-10<br /> Description of what is in the file<br /> */<br /></b></div><br /> Variable names should be meaningful so additional comments are not necessary to explain what the variable does. Example:<div><b style="color: #000000; line-height: 0.5em;"> int nNum; <span style="color: #008800;">//Bad</span><br /> int nNumOfTypes <span style="color: #008800;">//Good</span><br /></b></div><br />
A lower case prefix should be fitted to the variable name to help describe it at a glance:
n int
c character
b Boolean
f fload
d double
s C-style null terminated string OR a string object
p Pointers
Ex <table border="1" cellspacing="3" cellpadding"5"> <tr style="border: 1px solid #000000; text-align: center;"> <th>Prefix</th> <th>Data Type</th> <th>Example</th> <tr style="border:1px solid #000000; text-align: center;"> <td>n</td> <td>int</td> <td>nNumOfSignals</td>cCharPassed </tr> <tr style="border: 1px solid #000000; text-align: center;"> <td>c</td> <td>char</td> <td>cTypeMode</td> </tr> <tr style="border: 1px solid #000000; text-align: center;"> <td>b</td> <td>boolean</td> <td>bIsTrue</td> </tr> <tr style="border: 1px solid #000000; text-align: center;"> <td>f</td> <td>float</td> <td>fLength</td> </tr> <tr style="border: 1px solid #000000; text-align: center;"> <td>d</td> <td>double</td> <td>dWidth</td> </tr> <tr style="border: 1px solid #000000; text-align: center;"> <td>s</td> <td>C-Style null terminated string<br />OR a String object</td> <td>sUserInput</td> </tr> <tr style="border: 1px solid #000000; text-align: center;"> <td>p</td> <td>pointers</td> <td>pnNumOfSignals</td> </tr> <tr style="border: 1px solid #000000; text-align: center;"> <td>m_</td> <td>Data Member/<br />Instance Variable</td> <td>m_pnNumOfSignals<br /><b>NOT</b><br />pnm_NumOfSignals<br /><b>OR</b><br />mpn_NumOfSignals</td> </tr></table> All variable declarations should be done on their own lines!
Also There should be NO single character names for Classes, ALL Data Member should have a m_ prefixed to the name to show that it is a Data Member variables ( Instance Variables )Ex:int m_nType;NOTint nm_Type OR INT mn_Type;i, j, k, etc) except for arbitrary counters, such as for for loops
All variable declaration const and #define Variable names should be done on it's own linein All Caps
There should be NO single character names for variables (ExExample: i, j, k, etc) except for arbitrary counters, such as for loops<br /><div><b style="color: #000000; line-height: 0.5em;"> const int nMAX_TRIPS;<br /> #define MAX_TRIPS 1<br /></b></div><br />
All const and #define Variable names should be in All Caps
ex:
const int MAX_TRIPS;
#define MAX_TRIPS 1
Pointers should be defined in C++ style:
int* x;
NOT
int * x; OR int *x;
Pointers should be declared in C++ style:
 
Example:<br />
<div>
<b style="color: #000000; line-height: 0.5em;">
int* x;<br />
NOT<br />
int * x; OR int *x;<br />
</b>
</div>
<br />
 
Class names should be all lower case except for the first letter, which should be upper case.
 
Function names should have meaningful names (They do not require prefix).
Function names should have meaningful names (they do not require prefix)
Function names Should be all lower case except for the First letter of each Word.
 Example:<br /><div><b style="color: #000000; line-height: 0.5em;"> GetChar();<br /> NOT<br /> getChar(); OR Getchar();<br /></b></div><br />  Each function should have only one point of entry and one point of exit.! I.E. There should be only 1 return statement in each function.
Each function should have a header describing what it does.
Use Inline comments to describe hard to read code. All inline code should be set to the same indention as the code it is describing.
 
Example:<br />
<div>
<b style="color: #000000; line-height: 0.5em;">
//Comment<br />
GetChar();<br />
NOT<br />
//Comment<br />
GetChar()<br />
</b>
</div>
<br />
Opening braces should be on the same line as the defining function/if/else if/etc statement.
Ex:
void FunctionOne(int){
if (x > y){
NOT
void FunctionOne(int)
{
if (x > y)
{
Example:<br />
<div>
<b style="color: #000000; line-height: 0.5em;">
void FunctionOne(int){<br />
if (x > y){<br />
NOT<br />
void FunctionOne(int)<br />
{<br />
if (x > y)<br />
{<br />
</b>
</div>
<b>
There should be NO use of the tab character!!!
Each indent should be 3 blank spaces! I will write a wiki on how to set this up in VS 2008, VS 2010,And Notepad++
</b>
 
</pre>
<br /> <br />
1
edit

Navigation menu