When writing functions, a few things need to be kept in mind:
Use verbs for naming your functions. Verbs, in English language, refer to names of actions. For example, jump
, get
, set
, go
, etc. are examples of verbs. This is a nice introduction to verbs from Khan Academy.
Make sure the function is as little coupled with its environment as possible.
Write pure functions whenever possible. Avoid intertwining your logic and IO operations, so your logic remains testable and reusable.
Do not create a function that is doing too many things. Keep functions small. A function should only do what it's name suggests. Same principle apply to classes as well.