These are listed in no particular order, but are numbered so they can referenced more easily.
- No interface should accept data that is not necessary for it to do its job. "Interface" includes: HTTP APIs (e.g. REST), function & method signatures, and React Component props, among others.
- Functions and methods should never mutate their arguments. Avoid patterns that rely on mutation of arguments.
- Prefer "flatter" codepaths. Nesting lots of
elsestatements is hard to follow and re-organize. Bail early using
returninstead of nesting subsequent code.
- Prefer flat data structures instead of deeply nested objects.
- If the majority of a routine is inside a loop, extract the core of the loop into a separate routine that operates on a single item.
- Extract magic strings and numbers from logic. At minimum, they should be declared as constants at the top of the file that uses them. Ideally, constants that influence observable behavior should be provided by a const