WORK IN PROGRESS (Basically we favor functional programming)
This document seeks to codify the opinion of Demergent Labs as it pertains to the source code of its umbrella projects. Code reviews will be subject to these guidelines. The document may change over time.
The intended meaning of favor is to use wherever practical. Always consider using the favored practice first before deeply considering alternatives. If there is a very good reason not to favor a practice, then be prepared to defend that claim.
- Favor functional programming
- Favor pure functions
- Favor immutable data
- Manage side-effects and side-causes appropriately
- Favor declarative programming
- Seek to describe what and not how
- Favor descriptive directory, file, function, and variable names
- Functions should never have more than one level of branching
- Functions should be composed of multiple one-line statements
- Prefer recursion over iteration
- Prefer higher-order array operations (map, filter, reduce, etc) versus loops with mutations (for, while, etc)
- No classes
- Declare named functions at the top level using the
function
keyword syntax - Never declare named functions within functions, always declare them at the top level
- All anonymous functions should use the arrow syntax
- Use const for variables and values intended to be immutable
- Use let for variables and values intended to be mutable
- Never use var
- Don't throw errors, always return a value
- Be prepared to defend every use of
mut
- All mutations should be performed in the top-level canister method
We'll see how many of these we can fix with prettier and a linter
- No TypeScript errors
- Imports in alphabetic order
- Directories, files, modules, and functions appropriately declarative
- No more than one level of branching within a function
- Functions should be a series of single statements
- They should read like a simple sentence
- Repeated code is sufficiently generalized