Subroutines: Why use them?
There are a number of very good reasons for using subroutines:
Modularity
Using subroutines helps to make your program more modular. That means that in identifying possible subroutines you will be automatically breaking it down into smaller functional units. This helps you to cope with a large task by “divide and conquer”.
Code re-use
One subroutine can be called from several places within a program. You may even be able to copy a subroutine from one program and use it intact or with small changes in another.
Incremental debugging
A very powerful technique is to write your program one subroutine at a time, and debug each subroutine before moving on. It is usually easier to debug a single subroutine on its own, because you can preset its inputs more easily, and because you remain focused on a relatively small piece of code.
Better documentation
If you place a descriptive comment at the start of each subroutine, almost like a mini-specification, it will make it so much easier to come along in a few days, months or even years and understand what is going on.