My common day-to-day use is “something that is used to generate individual parts of something, and that I might write alternative versions of in future”.
Here the use of a function lets you replace a generator with a different generator. Such examples occur frequently in OOP, but are only truly dependent upon functions.
- Draw a graph on screen (using turtle in python, or drawing rectangles at heights – anything will do)
- At first, have it draw y = 0. Then draw y=x.
Replace the bit that chooses y with a call to a function.
- Have the students write their own functions, and replacing only one line of code to get massively different effects
- If your language supports it, you can have the user type the name of a function, and it will graph that function
…the point being: it allows modularised code that returns a value which is then used repeatedly with different parameters within a larger program, without the two bits of code being coupled together.
My favourite “fancy” example (for which I have extensive video clips and actual code I’ve written and used in production) is in 3D. Here I draw 3D terrains using a function to provide a Z height for each X,Y co-ordinate: