Notes
How do you know when you need a function?
- start with the problem: what are you trying to
accomplish?
- break that problem down into steps
- are there repeated steps? These can be converted
into a function that is called multiple times.
- are there discreet tasks? a specific calculation or
value validation? all of these are good candidates for
functions
Once you've identified where you need a function, you
can think about specific inputs (parameters) and outputs
(return or results)
- does your function need information from the call
source? If so...
- how many parameters are needed?
- what types?
- will the values need to be validated?
- what output will the function perform?
- if the function determines a single
value, then an explicit return
is probably best
- if the function does something, a
result or series of results may be all that's needed