Advantages of Routines

The following list summarizes some of the advantages of using routines:

  • Reducing duplicated code

  • Reusing 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 ...

Get Start Here!™ Fundamentals of Microsoft® .NET Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.