Abstraction
Abstraction is another very general programming pattern that applies to more than just modular programming. Abstraction is essentially the process of hiding complexity: separating what you want to do from how to do it.
Abstraction is absolutely fundamental to all computer programming. Imagine, for example, that you had to write a program that calculates two averages and then figures out the difference between the two. A simplistic implementation of this program might look something like the following:
values_1 = [...] values_2 = [...] total_1 = 0 for value in values_1: total = total + value average_1 = total / len(values_1) total_2 = 0 for value in values_2: total = total + value average_2 = total / len(values_2) difference = abs(total_1 - total-2) print(difference)
As you can see, the code that calculates the average of a list of numbers is repeated twice. This is inefficient, so you would normally write a function to avoid repeating yourself. This can be done in the...