#
Styling
#
C#
#
Blocks
Use braces around multi-line blocks.
// good
if (condition)
{
return true;
}
// acceptable
if (condition) return true;
// bad
if (condition)
return true;
#
Comments
Prefix comments with "NOTE" or "TODO" as necessary to indicate items needing follow-up.
#
Enumerations
Use explicit values for publicly exposed enumerations in shared libraries.
Provide a value for zero preferring “None” or “Empty” as the name. This will be the default.
#
Whitespace
Place the opening brace on a new line (note the difference from JavaScript).
// good
if (condition)
{
return true;
}
// bad
if (condition) {
return true;
}
Surround operators with a single space.
// good
var total = price * quantity;
// bad
var total=price*quantity;
End files with a single newline character
#
Other
Include using directives when possible to avoid unnecessary namespace qualifications.
Use implicit typing with the var keyword for local variables when the type of the variable is obvious from the right side of the assignment or when the precise type is not important.
// good
var list = new List<String>;
// avoid
string total=price*quantity;
#
SQL
Reference external databases through views instead of creating direct references within stored procedures.
DO NOT use three part names when referencing objects within the same database.
Use meaningful aliases when joining tables.
-- good
SELECT
U.User_Ref
, R.Rank_Name
FROM
dbo.tbl_User AS U
INNER JOIN
dbo.tbl_Rank AS R
ON U.User_Rank_Ref = R.Rank_Ref;
-- bad
SELECT
tbl_User.User_Ref
, tbl_Rank.Rank_Name
FROM
dbo.tbl_User
INNER JOIN
dbo.tbl_Rank
ON tbl_User.User_Rank_Ref = tbl_Rank.Rank_Ref;
-- bad
SELECT
A.User_Ref
, B.Rank_Name
FROM
dbo.tbl_User AS A
INNER JOIN
dbo.tbl_Rank AS B
ON A.User_Rank_Ref = B.Rank_Ref;
End statements with a semicolon (;).
#
JavaScript (ASP.NET)
#
Variables
Declare all variables with the var keyword.
Prefix internal variables with an underscore (_) when using the module pattern.
#
Conditionals
Prefer === and !== over == and !=.
#
Blocks
Use braces around multi-line blocks.
// good
if (condition) {
return true;
}
// acceptable
if (condition) return true;
// bad
if (condition)
return true;
#
Whitespace
Place the opening brace on the same line (note the difference from C#).
// good
if (condition) {
return true;
}
// bad
if (condition)
{
return true;
}
Surround operators with a single space.
// good
var total = price * quantity;
// bad
var total=price*quantity;
End files with a single newline character.