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/03/19 23:03] – [Comma Separated Lists] stephen | stephens_coding_standards [2017/01/01 20:05] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ===== Commented Code ===== | ===== Commented Code ===== | ||
| - | No commented code, unless there is a comment clearly explaining under what circumstances the code should be uncommented. 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 33: | Line 33: | ||
| ===== Tabs Versus Spaces ===== | ===== Tabs Versus Spaces ===== | ||
| - | Use tabs to indent, spaces to align. Tabs should only appear at the beginning of a line | + | Use tabs to indent, spaces to align. Tabs should only appear at the beginning of a line. No arguments, no debates, this is how things are done at TallGuyProgramming Inc. |
| - | No arguments, no debates, this is how things are done at TallGuyProgramming Inc. | + | |
| < | < | ||
| Line 44: | Line 42: | ||
| → Customers | → Customers | ||
| </ | </ | ||
| + | |||
| + | ===== Date Format ===== | ||
| + | |||
| + | In all internal documents, code comments etc. dates will be written in the [[http:// | ||
| + | |||
| + | **'' | ||
| + | |||
| + | For example, 2001-01-01, 1956-12-31. | ||
| + | |||
| + | **No other date formats are acceptable.** The year shall not be abbreviated to two digits. The separator shall not be a slash or a comma or anything else. And don't even think about putting the year, month and day in a different order. | ||
| + | |||
| + | 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 ===== | ||
| + | |||
| + | No line of code shall exceed 130 characters in length. Tabs count as four characters in this context. Use the **Col** value in the lower right of Visual Studio. | ||
| + | |||
| + | 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 ===== | ||
| + | |||
| + | 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.1332198184.txt.gz · Last modified: 2017/01/01 19:53 (external edit)
