# Code Conventions

# Patterns

# DRY - Don't repeat yourself

  • avoid doing the same again and again

# SoC - Separation of concerns

  • a module has a/one purpose
  • a function has a/one purpose

# Kiss - Keep it simple, stupid

  • Avoid synthetic complexity -> the domain itself is complex enough!
  • Do not over-engineer!
  • Focus on the goal
    • Do not generalize if not needed (yet)
    • Do not implement "perhaps it will be needed in future" things
    • Do not pre-optimize
    • Always re-read your code:
      • Is it easy to understand?
      • Is the level of abstraction fitting the requirements?
    • Aware of what your colleagues ask or mention in pull requests:
      • Do they ask (a lot) for explanations?
      • Do they think it's hard to follow the data-flow?
      • ...

# Early out and Guard clauses

  • instead of wrapping all the code with conditions, think about having the business code on top level
  • "guard clauses" prevent you from this
// wrapping callback based functions (parameter is a callback) with promises
return new Promise((resolve, reject) => {
    cbFunction((data, error) => {
        if (error) { // "guard clause"
            return reject(error); // "early out"
        }
        return resolve(data);
    })
});

# Avoid deep nesting

  • nested conditions (see early out/guard clauses)
Page Info: Created by GitHub on Jun 9, 2023 (last updated a minute ago by GitHub)