Introduction to Programming/Subprograms

From Wikiversity
Jump to navigation Jump to search

It is an unfortunate fact of life that things break—and computer programs are certainly no exception. One of the things that engineers have learned is that, in general, complex things break more often than simple things. Unfortunately, even a well built program can be tremendously complicated. Something like Microsoft Windows XP is probably more complicated than the Space Shuttle. It isn't surprising then, that software has bugs.

In many disciplines, including mathematics, it is a common to solve big, complicated problems by breaking them down into a group of smaller, simpler problems. That is the basic principle behind subprograms. Rather than write one big, complicated program that solves the entire problem, we can write several small pieces of a program that each solve part of the problem and, then, combine them together, in some specific way, to solve the entire problem.

Subprograms go by different names—depending on the programming language being used.

Note: the difference between a procedure (or subroutine) and a function is that functions return a result, whereas procedures do not. In some languages, such as C# this distinction is implicit. In others, such as Pascal, it is explicit.