diff --git a/docs/WorkflowGuidelines.md b/docs/WorkflowGuidelines.md index 42b67893..a5f2f35f 100644 --- a/docs/WorkflowGuidelines.md +++ b/docs/WorkflowGuidelines.md @@ -163,7 +163,6 @@ make use of the type system whenever you can, for example: * Do not use edge-values to denote absence of value. Example: use null (`Nullable`) instead of `DateTime.MinValue`. - * Use Option types instead of Nullable ones if your language provides it (e.g. if you're using F# instead of C#). * Do not use `undefined` which is a pitfall from JavaScript (the fact that it has two kinds of null values is a defect in its design). As we're using TypeScript we should be able to avoid the ugliness of JavaScript. @@ -173,6 +172,26 @@ { return 0; } + return 1; + ``` + + Improved code: + ```typescript + if (TypeHelpers.IsNullOrUndefined(foo)) + { + return 0; + } + return 1; + ``` + + * Use Option types instead of Nullable ones if your language provides it (e.g. if you're using F# instead of C#). + + Example (with bad practice): + ```typescript + if (TypeHelpers.IsNullOrUndefined(foo)) + { + return 0; + } else { return 1; @@ -181,7 +200,11 @@ Improved code: ```typescript - return foo ? 1 : 0; + let bar = OptionStatic.OfObj(option); + if (bar instanceof None) { + return 0; + } + return 1; ``` * Abusing obscure operators or the excessive multi-facetedness of basic ones: