stephens_coding_standards
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
stephens_coding_standards [2012/05/22 23:40] – [Unnecessary Parentheses] stephen | stephens_coding_standards [2017/01/01 20:05] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <term YAGNI> | ||
- | |||
====== Stephen' | ====== Stephen' | ||
===== Commented Code ===== | ===== Commented Code ===== | ||
- | No commented code, unless there is a comment clearly explaining under what circumstances the code should be uncommented. The YAGNI principle should be kept in mind. If there are no circumstances in which the code should be uncommented, | + | No commented code, unless there is a comment clearly explaining under what circumstances the code should be uncommented. The < |
**Justification: | **Justification: | ||
Line 47: | Line 45: | ||
===== Date Format ===== | ===== Date Format ===== | ||
- | In all internal documents, code comments, file names etc. **all** | + | In all internal documents, code comments etc. dates will be written in the [[http:// |
**'' | **'' | ||
Line 56: | Line 54: | ||
Note: This does not mean that software will use this format to display dates to the user. Dates displayed to the user should follow the system' | Note: This does not mean that software will use this format to display dates to the user. Dates displayed to the user should follow the system' | ||
+ | |||
+ | When a date is used in a file name, directory name or source control tag or branch, the following variant of the [[http:// | ||
+ | |||
+ | **'' | ||
+ | |||
+ | For example, 20010101, 19561231. | ||
===== Line Length ===== | ===== Line Length ===== | ||
Line 62: | Line 66: | ||
To get a visual margin guide in Visual Studio 2010, ensure the Productivity Power Tools extension is installed, right click the 130th column and select Guidelines -> Add Guidelines from the context menu. | To get a visual margin guide in Visual Studio 2010, ensure the Productivity Power Tools extension is installed, right click the 130th column and select Guidelines -> Add Guidelines from the context menu. | ||
+ | |||
+ | ===== Blank Lines ===== | ||
+ | |||
+ | Code shall not contain more than one blank line in a row. There' | ||
===== Unnecessary Parentheses ===== | ===== Unnecessary Parentheses ===== | ||
Code shall not contain unnecessary parentheses. Developers are expected to be able to use [[http:// | Code shall not contain unnecessary parentheses. Developers are expected to be able to use [[http:// | ||
+ | |||
+ | ===== Pointless Boolean Expressions ===== | ||
+ | |||
+ | The following boolean expressions are pointless and are not allowed: | ||
+ | |||
+ | <code c#> | ||
+ | booleanExpression == true // Use booleanExpression | ||
+ | booleanExpression != true // Use !booleanExpression | ||
+ | booleanExpression == false // Use !booleanExpression | ||
+ | booleanExpression != false // Use booleanExpression | ||
+ | |||
+ | if (booleanExpression) | ||
+ | return true; | ||
+ | return false; | ||
+ | // Use return booleanExpression; | ||
+ | |||
+ | if (booleanExpression) | ||
+ | return false; | ||
+ | return true; | ||
+ | // Use return !booleanExpression; | ||
+ | </ | ||
+ | |||
+ | Developers are expected to know and understand how boolean expressions work, how to express them in the simplist form possible, and understand and use the '' | ||
+ | ===== String Comparisons ===== | ||
+ | |||
+ | The standard comparison operators < | ||
+ | |||
+ | When using the '' | ||
+ | |||
+ | The '' | ||
+ | |||
+ | ==== Which StringComparison should be used? ==== | ||
+ | |||
+ | * To do a comparison like a machine, use '' | ||
+ | * To do a comparison like a human, use '' | ||
+ | * It is extremely unlikely that '' | ||
+ | |||
+ | ==== Machine or Human? WTF? ==== | ||
+ | |||
+ | The German alphabet has the letter ' | ||
+ | |||
+ | <code c#> | ||
+ | String.Compare(" | ||
+ | String.Compare(" | ||
+ | </ | ||
+ | |||
+ | (In this example it does not seem to matter what the current culture is set to, but there will be other examples where it does.) | ||
+ | |||
+ | ===== CurrentCulture vs CurrentUICulture ===== | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code c#> | ||
+ | (date, currency, double).ToString = CultureInfo.CurrentCulture | ||
+ | |||
+ | resource.fr-CA.resx file = CultureInfo.CurrentUICulture | ||
+ | </ | ||
+ | |||
+ | ===== Switch Case ===== | ||
+ | |||
+ | * If a Switch Case is intended to cover **every** case, it must include a '' | ||
+ | * If a Switch Case is intended to only cover **some** cases, it must include a comment to that effect. | ||
+ | |||
+ | ===== Exceptions ===== | ||
+ | |||
+ | Exceptions shall not be ' | ||
+ | |||
+ | <code c#> | ||
+ | // Career limiting code: | ||
+ | catch (Exception ex) | ||
+ | { | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Thou shall not throw a **new** exception in a '' | ||
+ | |||
+ | <code c#> | ||
+ | // Career limiting code: | ||
+ | catch (Exception ex) | ||
+ | { | ||
+ | throw new Exception(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Id ===== | ||
+ | |||
+ | The correct capitalisation of ' | ||
+ | |||
+ | ===== SQL ===== | ||
+ | |||
+ | ==== Capitalisation ==== | ||
+ | |||
+ | Keywords are upper cased ('' | ||
+ | |||
+ | Functions are upper cased ('' | ||
+ | |||
+ | Built in types are lower cased ('' | ||
+ | |||
+ | Variables, table aliases and column aliases are title cased. | ||
+ | |||
+ | The names of user database objects are title cased (tables, columns, views, stored procedures etc.) | ||
+ | |||
+ | ===== Web.config ===== | ||
+ | |||
+ | The ''< | ||
{{tag> | {{tag> | ||
stephens_coding_standards.1337730047.txt.gz · Last modified: 2017/01/01 19:53 (external edit)