C# Coding Standard
To guide the development of C# Programs, and to ensure that each logical line (as documented
Purpose
in corresponds to one physical line.
Program
Begin all programs with a descriptive header.
Headers
/******************************************************************/
/* Program Assignment: the program number */
/* Name: your name */
Header example
/* Date: the date you started developing the program */
/* Description: a short description of the program and what it does */
/******************************************************************/
Use descriptive names for all variables, function names, constants, and other identifiers.
Use single letter identifiers only for the counter in loops.
Follow the style:
Identifiers Identifiers start with lower case.
Multi-word identifiers are internally capitalized.
Do not use hyphens or underscores to separate multi-word identifiers.
private static float sumDiffSquares = 0; //this is good
Identifier private static float x = 0; //this is bad
Example private static float sum_Diff_Squares = 0; //this is bad
Comments Allways use // for comments and in new line
private static float sumDiffSquares = 0;
//this is Good
if (foo > 1)
{
// Do comment.
...
}
Comments Else
{
Examples return false; // this is wrong, use new line.
}
/*
This comment is wrong
Allways use //
*/
// This comment is OK
Blank Spaces Use one blank space to separate classes and methods.
Follow the:
Open braces (i.e. "{") start a new line.
Indenting Close braces (i.e. "}") start a new line
if statements always use braces {}.
Indenting for (int i=0; i < [Link]; i = i + 1)
{
[Link](new Float (args[i]), i);
}
if (condition) // this is bad! THIS OMITS THE BRACES {}!
statement;
if (condition)
{
// this is correct!
statement;
}
if (condition)
{
statements;
}
else if (condition)
{
statements;
}
else
Example {
statements;
}
while (condition)
{
statements;
}
try
{
statements;
}
catch (ExceptionClass e)
{
statements;
}
finally
{
statements;
}
Follow style:
Classes and Interfaces begin with a capital letter.
Packages are all lower case.
Methods begin with a capital case letter.
Capitalization
Multi-word identifiers are internally capitalized in methods.
The names of variables declared class constants should be all uppercase with words
separated by underscores (“_”).
Capitalization public class MeanStd
private static Vector vals = new Vector();
Examples
private static Vector diffSquares = new Vector();
package [Link]
static final int MAX_WIDTH = 999;
Each class should be contained in its own file.
Program
Each file should be named as the name of the class contained within it.
Modules
Packages are preferred.
Each line should contain at most one statement.
Statements
One declaration per line
argc++; // Correct
argv++; argc--; // this is bad!
Statements int level;
Examples int size;
[Link] = [Link] = 'c'; // this is bad!
Métodos En la misma línea que se define el método agrego /*@Method*/
Clases Empieza la definición de la clase con la palabra clave class y agrego un comentario al final
/*@EndClass*/