The following list summarizes some of the advantages of using routines:
Reducing duplicated code
Simplifying complex code
Hiding implementation details
Dividing tasks among programmers
Making debugging easier
The only major disadvantage to using routines is that doing so adds some overhead to the program. When a piece of code invokes a routine, the program must prepare the routine for execution, and it must store some information so that it can return to the correct location in the code that called the routine after the routine finishes. This overhead is usually small, so it doesn’t cause much of a problem unless a program calls a routine a very large number of times.
For example, suppose that a program contains a loop ...