Functions in action
If we again go back to our application for turning on the lights outside our house and focus on the application running on our phone, we will see that we have at least two distinct things we need to do over and over again.
We will need to get our current position and we need to calculate our distance to home so we know whether it is time to turn on the lights or not.
These are two distinct tasks, and they are very well suited to being packaged up into two different functions, namely,
calculate_distance_to_home, as shown in the following figure:
This diagram shows that we have a block that we call
main_application. This is a function, and it calls a function called
get_current_position that will return the longitude and latitude, indicating the current position of the phone. Equipped with this information,
main_application can now make...