Skip to content

Commit

Permalink
docs/WorkflowGuidelines.md: improve FP rules
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Sep 10, 2024
1 parent 34c5a37 commit 6807c3d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions docs/WorkflowGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateTime>`) 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.

Expand All @@ -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;
Expand All @@ -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:
Expand Down

0 comments on commit 6807c3d

Please sign in to comment.