Difference between revisions of "Team !YOU - Official Standards"

From CDOT Wiki
Jump to: navigation, search
(Coding Standards)
Line 106: Line 106:
   const int CONTANT = 100;
   const int CONSTANT = 100;
   #define CONSTANT;
   #define CONSTANT;

Latest revision as of 23:51, 31 January 2010

Team !You - To the main team page.

Standards Discussion - To the standards discussion page.

Official Standards

Below are the standards that our team will follow while programming our project. As stated during our IRC meeting, these standards may be changed if the team deems necessary.

Declare only one variable in each line.

This makes it easier to scan the code and find the type of a variable that you see somewhere else in the code.


 int a;
 int b = 0;
 int c = a;


 int a, b = 0, c = a;


Indent = 2 spaces

The tab space is interpreted different across different software and operating systems. Use normal spaces to add indentation instead.

Note : Most text editors have the option to switch tabs into spaces, this helps so you don't have to press the space so many times.

Use Include Guides for Header Files

For every header file that we write, we must make sure that it will never be added more than once to different pieces of code. Therefore, all your header file code should be in between the include guides as shown below:

 #ifndef _344_EXAMPLE_H_
 #define _344_EXAMPLE_H_

The convention for this project is to define our header files in upper case, starting with 344, and enclosed in a single underscore(_)

Put the pointer identifier(*) right after the target variable type.

Pointers are hard enough to deal with. It only makes it more complicated if they are declared differently throughout the code.


 int* p1;
 char* p2;


 int *p1;
 char *p2;

Use of iterating variables on for loops

Since we will be writing code in both C and C++, we must declare all of our variables at the top of the program, including iteration(for loop) variables.


 int i;
 for(i = 0; i < 5; i++) {


 for(int i = 0; i < 5; i++) {

Variable names

We will be using small camel notation for variable names. Use descriptive names, and allowed to use abbreviations when obvious.


 int numOfStudents;
 int studNumber;
 char* firstName
 char* lastName


 int NumberOfStudents;
 int StudentNumber;
 char* StudentFirstName;
 char* StudentLastName;

Use of comments

Since we will be writing code in C and C++, we MUST only use /* comment */ for comments. Native C compilers do not know how to handle end of line comments(//), so please don't use them.

Nesting and Block Format

Here is how we are going to deal with nesting statements, also where we are going to be placing the braces. Do:

 if(something == 1) {
   printf("something = 1\n");
 else {
   printf("something != 1\n");

Above you see that we have the else statement on it's own line. We also have the opening brace on the same line as our statement.


We have decided to use const instead of the define command. Const allows us to define a type, which allows for better error messages when trying to debug the code.


 const int CONSTANT = 100;


 #define CONSTANT;