I’d like to add a few more points about “easy to reason” functions from Robert C. Martin’s book, Clean Code.
According to Martin, functions should…
- do only one thing (error handling, conditional checks, and loops are one thing)
- hardly ever be more than 20 lines long
- contain one level of abstraction
- use descriptive names and have consistant naming schemes
- ideally have zero arguments, followed by one, then occasionally two and hardly ever three
- avoid flag input arguments and output arguments
- either do something or answer something, but not both
- avoid duplicating code
The whole book, for me, was a good read.