Imagine a program with 1000 lines. (This may seem large to you, but it is actually quite small.) It is much easier to write a properly designed program consisting of 20 50-line functions than it is to write a program consisting of one 1000-line main program. Functions can be written and understood independently of one another. It is much easier to get your mind around a 50-line thing than a 1000-line thing.

Another benefit is that code can be reused between projects. If someone has previously written a function that you would like to use, it is a simple matter to incorporate it into your program.

A third benefit is that the use of functions can eliminate the duplication of code. If the duplicated code is long enough, the use of functions can actually shorten a program.

Return to lesson.