Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit



C# Program Coding Standards

 

These are the coding standards we’ll use in IGME 106.

Take the time to read through this, and refer to it whenever you’re unsure of a particular syntax standard.

 

Data Types:

1. Data types must be explicitly declared.  The use of var is unacceptable in this course.  

Naming and Case Conventions:

1. Names used for classes, methods and variables are expected to be meaningful.  Loop control variables (like i or x) can be a single letter.

double interestRate;

for(int i = 0; i < 4; i++)

 

2. Variable names start with lowercase letters and utilize camelCase.  

float speed;

int colliderWidth;

Vector3 velocity;

Vehicle redCar;

 

3. Do not use name multiple times in the same scope, differing only in case:  

number vs. Number vs. NUMBER

 

4. Multiple classes can use the same name for a class field.

class Animal and class Car can both contain a field called name

 

5. Class names are always capitalized.  If the name has multiple words, each word is capitalized using UpperCamelCase.

class Vehicle { … }

class EnemyShip { … }

 

6. Method names always start in uppercase.  If the name has multiple words, each word is capitalized using UpperCamelCase.

double CalculateInterest() { … }

bool DetermineCollision() { … }

 

7. Constant names should start with an uppercase letter.

const int DaysInWeek = 7;

Comments:

1. You are expected to comment your code. Some percentage of each assignment’s grade may be based on the comments provided.

2. Each class should have a comment block (called a “class header” comment) associated with it.  These headers will contain the following information:

a. Author (you!)

b. The associated assignment

c. Purpose of the class

d. Restrictions on the usage or known errors

3. Each method should have a comment block (called a “method/function header” comment) associated with it.  You may want to use the magical triple-slash comments. These headers will contain the following information:

a. Purpose of the method

b. Restrictions on the usage or known errors

c. Other appropriate sections, like parameters or return values

4. Comment sections of code where you are doing something clever, unusual or where you are making use of some obscure feature.

5. Don’t comment the obvious unless specifying intent:

Useless Comment:

Debug.Log(“”);    // Prints blank line   (duh!)

Better Comment

Debug.Log(“”);    // Improve output & input spacing


Code Statements:

1. Only one variable declaration per line.

Good example:  

int characterWidth;

int characterHeight;

 

Unacceptable example:  

int characterWidth, characterHeight, speed;

 

2. Only one code statement per line.

Good example:  

if(alive)

{

    shipSpeed += 0.2;

}

 

Unacceptable example:  

if(true) Console.WriteLine(“this is true”);

 

3. Use indentation and curly brackets to indicate the scope of functions and various control structure, like loops, and if statements.  

Good example:  

for(int x = 200; x > 10; x = x - 20)

{

    Console.WriteLine (“x is ” + x);

}

 

Unacceptable examples:  

for(int x = 200; x > 10; x = x - 20) { Console.WriteLine (“x is ” + x);        }

 

for(int x = 200; x > 10; x = x - 20) {

Console.WriteLine (“x is ” + x);        }

 

 for(int x = 200; x > 10; x = x - 20)

Console.WriteLine (“x is ” + x);