Difference between revisions of "Team Excellence - oop344 20113 Code Standards"

From CDOT Wiki
Jump to: navigation, search
(Indents)
(Class Standards)
 
(28 intermediate revisions by 3 users not shown)
Line 2: Line 2:
  
 
= Code Standards =
 
= Code Standards =
Fardad suggested in class today that we make a document that defines the format that our code is presented in so I've made this page to outline them.
 
  
The sections that follow are just ones that I could think of. If you know of other things feel free to add them
+
'''Sandip:'''
 +
I have a proposal. How about doing it like this:
 
== If Statement ==
 
== If Statement ==
<syntaxhighlight lang="cpp">
 
if (condition){
 
  stuff;
 
}
 
else if (condition){
 
  stuff;
 
}
 
else {
 
  stuff;
 
}
 
</syntaxhighlight>
 
Notice the space between the 'if' and '(' and the lack of a space between the ')' and '{'. Also the 'else' starts a line under the '}'.
 
  
If the "stuff" is only one line the curly braces can be omitted.
 
  
 
'''Dzmitry:'''
 
'''Dzmitry:'''
Line 26: Line 13:
 
if (condition){
 
if (condition){
 
     stuff;
 
     stuff;
}else if (condition){
+
} else if (condition){
 
     stuff;
 
     stuff;
}else{
+
} else{
 
     stuff;
 
     stuff;
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
That will save a few lines, also space between "stuff" and beginning of the line should be default Visual Studio Tab (Mine is 4 spaces).
+
That will save a few lines, also space between "stuff" and beginning of the line should be default Visual Studio Tab (Mine is 4 spaces).  
 +
 
 +
'''Jitender:'''
 +
Guys, we should agree one of the standard, I agree with Dzmitry proposal, it short and easy to follow
  
 
== For Loop ==
 
== For Loop ==
Line 43: Line 33:
  
 
Similar deal as with the if statement if "stuff" is only one like the curly braces can be omitted.
 
Similar deal as with the if statement if "stuff" is only one like the curly braces can be omitted.
 +
 
== While Loop ==
 
== While Loop ==
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
Line 52: Line 43:
  
 
Also the curly braces can be omitted if "stuff" is only one line.
 
Also the curly braces can be omitted if "stuff" is only one line.
 +
 
== Function Declarations ==
 
== Function Declarations ==
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
Line 61: Line 53:
  
 
Also there's no space between the ')' and '{'.
 
Also there's no space between the ')' and '{'.
 +
 
== Indents ==
 
== Indents ==
 
I think each indent should be the equivalent of two spaces. You can change the settings of Visual Studio to put in 2 spaces whenever you press tab. This will keep the code properly aligned and if someone isn't used to using tab for indent they can easily just use two spaces.
 
I think each indent should be the equivalent of two spaces. You can change the settings of Visual Studio to put in 2 spaces whenever you press tab. This will keep the code properly aligned and if someone isn't used to using tab for indent they can easily just use two spaces.
Line 66: Line 59:
 
'''Dzmitry:''' I think at least 3-4 spaces will be better. First of all, it makes code easier to read (less characters on a page) and original console.cpp (at least for me) is written with 4 spaces spacing, so we won't need to change professor's code.
 
'''Dzmitry:''' I think at least 3-4 spaces will be better. First of all, it makes code easier to read (less characters on a page) and original console.cpp (at least for me) is written with 4 spaces spacing, so we won't need to change professor's code.
  
== Class Member Variables ==
+
== Class Standards ==
I think we should follow Fardad's lead and start all of our class' member variable names with an underscore '_' to differentiate them from other variables.
+
 
= Comments =
+
'''Header File Standards:'''
 +
<syntaxhighlight lang="cpp">
 +
/**
 +
class.h
 +
*  Sandip Patel 
 +
*  October 12, 2011
 +
**/
 +
 
 +
#ifndef _INITIAL_CLASS_
 +
#define _INITIAL_CLASS_
 +
 
 +
class CLASS {
 +
   
 +
          int _a;
 +
          int _b;
 +
 
 +
  public:
 +
          function();
 +
}
 +
 
 +
#endif
 +
</syntaxhighlight>
 +
 
 +
'''All Cpp File Standards:'''
 +
<syntaxhighlight lang="cpp">
 +
 
 +
/* Function Starts here */
 +
function name() {
 +
 
 +
      /* Header goes here */
 +
          int key = 0;          // Comment goes here
 +
          bool done = false;
 +
 
 +
      /* Again Important Header goes here */
 +
          if(condition){
 +
                stuffs;
 +
          }
 +
 
 +
      /* All Loops */
 +
          for(i=0; i<len; i++){
 +
              statements;
 +
          }
 +
         
 +
          while(condition){
 +
              statements;
 +
          }
 +
 
 +
}
 +
/* function ends here */
 +
</syntaxhighlight>
 +
 
 +
== Comments ==
 +
'''Dzmitry:'''
 +
<syntaxhighlight lang="cpp">
 +
int foo(int x);  // this comment is an example
 +
</syntaxhighlight>
 +
 
 
== File Header ==
 
== File Header ==
At the start of your files put a comment that defines the file and and declares when it was last updated and by whom
+
 
 +
'''Suggested By: Sandip Patel'''
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
// One Line File Name / Description
+
/**
// filename.h
+
*  test.cpp
//
+
*  Sandip Patel 
// Chad Pilkey
+
*  October 12, 2011
// Oct 13 2011
+
**/
// Version 1.0
 
//
 
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 23:53, 18 October 2011


OOP344 | Weekly Schedule | Student List | Teams | Project | Student Resources

Code Standards

Sandip: I have a proposal. How about doing it like this:

If Statement

Dzmitry: I have a proposal. How about doing it like this:

if (condition){	
    stuff;
} else if (condition){
    stuff;
} else{
    stuff;
}

That will save a few lines, also space between "stuff" and beginning of the line should be default Visual Studio Tab (Mine is 4 spaces).

Jitender: Guys, we should agree one of the standard, I agree with Dzmitry proposal, it short and easy to follow

For Loop

for (i=0; condition; i++){
  stuff;
}

Notice the space after the 'for' and the lack of space between the ')' and '{'

Similar deal as with the if statement if "stuff" is only one like the curly braces can be omitted.

While Loop

while (true){
  stuff;
}

Notice the space after the 'while' and the lack of space after the ')' and '{'.

Also the curly braces can be omitted if "stuff" is only one line.

Function Declarations

void foo(int a){
  stuff;
}

The function header isn't indented at all and the first line follows immediately after with one indent.

Also there's no space between the ')' and '{'.

Indents

I think each indent should be the equivalent of two spaces. You can change the settings of Visual Studio to put in 2 spaces whenever you press tab. This will keep the code properly aligned and if someone isn't used to using tab for indent they can easily just use two spaces.

Dzmitry: I think at least 3-4 spaces will be better. First of all, it makes code easier to read (less characters on a page) and original console.cpp (at least for me) is written with 4 spaces spacing, so we won't need to change professor's code.

Class Standards

Header File Standards:

/**
*   class.h
*   Sandip Patel  
*   October 12, 2011
**/

#ifndef _INITIAL_CLASS_
#define _INITIAL_CLASS_

class CLASS {
     
          int _a;
          int _b;

  public:
          function();
}

#endif

All Cpp File Standards:

/* Function Starts here */
function name() {

       /* Header goes here */
          int key = 0;           // Comment goes here
          bool done = false;

       /* Again Important Header goes here */
          if(condition){
                stuffs;
          }

       /* All Loops */
          for(i=0; i<len; i++){
              statements;
          }
          
          while(condition){ 
              statements;
          }

}
/* function ends here */

Comments

Dzmitry:

int foo(int x);   // this comment is an example

File Header

Suggested By: Sandip Patel

/**
*   test.cpp
*   Sandip Patel  
*   October 12, 2011
**/