Often functions will act upon global data, or data passed in by the caller. It is important that when the function completes, it leaves this data in a consistent state. Equally so, it is important that, the function can make assumptions about the data before it accesses it.
Designing functions
Pre- and post-conditions
A function will typically alter some data: values passed into the function, data returned by the function, or some global data. It is important when designing a function that you determine what data will be accessed and changed and that these rules are documented.
A function will have pre-conditions, assumptions about the data that it will use. For example, if a function is passed a filename, with the intention...