C# Coding Standard for Group Project
Entity Naming
Names
Indentation and Spacing
Comments
Declarations
Statements
Other Typographical Issues
Entity Naming
Public members, types and namespaces shall begin with an upper case letter.
All other variables shall begin with a lower case letter.
Constants shall begin with an upper case letter, shall be upper case and words shall be separated by underscore (_).
Names
Use sensible, descriptive names.
Do not use short cryptic names or names based on internal jokes.
It shall be easy to type a name without looking up how it is spelt.
Exception: Loop variables and variables with a small scope (less
than 20 lines) may have short names to save space if the purpose of
that variable is obvious.
Only use english names.
It is confusing when mixing languages for names.
English is the preferred language because of its spread in the
software market and because most libraries used already use english.
Variables with a large scope shall have long names, variables with a small scope can have short names.
Scratch variables used for temporary storage or indices are best kept
short.
A programmer reading such variables shall be able to assume that its
value is not used outside a few lines of code.
Common scratch variables for integers are i, j,
k, m, n and for characters c and
d.
Indentation and Spacing
Braces shall follow "Exdented Style".
The Exdented Bracing Style means that the curly brace pair are lined
up with the surrounding statement. Statements and declarations
between the braces are indented relative to the braces.
Braces shall be indented 4 columns to the right of the starting position of the enclosing statement or declaration.
Example:
No examples for Java yet
Loop and conditional statements shall always have brace enclosed
sub-statements.
The code looks more consistent if all conditional and loop statements
have braces.
Even if there is only a single statement after the condition or loop
statement today, there might be a need for more code in the future.
Braces without any contents may be placed on the same line.
The only time when two braces can occur on the same line is when they do not
contain any code.
Each statement shall be placed on a line on its own.
There is no need to make code compact.
Putting several statements on the same line only makes the code
cryptic to read.
The standard method of using three statements in a for loop is fine.
Declare each variable in a separate declaration.
This makes it easier to see all variables.
Lines shall not exceed 100 characters.
Even if your editor handles long lines, other people may have set up
their editors differently.
Long lines in the code may also cause problems for other programs and
printers.
Do not use tabs.
Tabs make the source code difficult to read where different programs
treat the tabs differently.
The same code can look very differently in different views.
Avoid using tabs in your source code to avoid this problem.
Use spaces instead.
Comments
Comments shall be written in english
All comments shall be placed above the line the comment
describes, indented identically.
Being consistent on placement of comments removes any question on what
the comment refers to.
Declarations
Declare class data private.
Classes shall encapsulate their data and only provide access to this
data by member functions to ensure that data in class objects are
consistent.
Statements
Do not use do-while loops.
do-while loops are less readable than ordinary while loops and for
loops since the conditional is at the bottom of the loop.
The reader must scan the entire loop in order to understand the scope
of the loop.
In addition, do-while loops are not needed.
Any do-while loop can easily be rewritten into a while loop or a for
loop.
Reducing the number of constructs used enhance readability.
Other Typographical Issues
Do not use literal/magic numbers
Use constants instead of literal numbers to make the code consistent
and easy to maintain.
The name of the constant is also used to document the purpose of the number.
Generated 2018-01-30 by Coding Standard Generator version 1.13.