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

From CDOT Wiki
Jump to: navigation, search
(Class Standards)
(If Statement)
Line 6: Line 6:
 
I have a proposal. How about doing it like this:
 
I have a proposal. How about doing it like this:
 
== If Statement ==
 
== If Statement ==
 +
 +
'''Sandip:'''
 +
I have a proposal. How about doing it like this:
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
 
if (condition)
 
if (condition)
Line 20: Line 23:
 
}
 
}
 
</syntaxhighlight>
 
</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:'''

Revision as of 16:21, 14 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

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

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

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).

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 _CLASS_
#define _CLASS_

class CLASS {
     
          int a;
          int b;

  public:
          function();
}

#endif

Comments

Dzmitry:

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

File Header

Suggested By: Sandip Patel

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