Functions are Friends#
Functions (methods) can be used to do all of the following:
Create descriptive landmarks in the flow of logic
Provide concise summary of inputs for a task
Encapsulate logic into small, testable blocks
Create reusable blocks of application logic
Provide a way to document the purpose of a block of code
Provide a way to document the expected inputs and outputs of a block of code
Provide a way to document the expected behavior of a block of code
Qualities of a good function#
A good function should have the following qualities:
Has a descriptive name that clearly communicates its purpose
Does one thing and does it well (Single Responsibility Principle)
Has a small number of parameters
Provides a single level of abstraction
Has no side effects
Is easy to understand and read (so not too big)