General reading
Tips
Writing functions
- A function should not rely on any globals (even in python and javascript)
- Conversely, all the dependencies a function needs should be passed in as parameters.
- Use default parameter values if you do not want to supply parameters for all calls.
- If you think you will have too many dependencies, use a service locator object as the last dependency which includes all the services a function would need. But read the next point.
- A function should only go between layers adjacent to each other. For example, a function which receives HTTP request should never directly talk to a database because HTTP and database are not adjacent layers. The layers could be HTTP -> Receiver -> Business logic -> Repository -> Database
- If a function is so simple that it can directly talk to two far away layers, introduce an abstraction in the middle.
Resources
Skills