A real-life example of a procedure is brushing your teeth. There are several steps involved in this process – getting your toothbrush, squeezing the toothpaste onto the brush, brushing all your teeth, rinsing your mouth out and putting everything back. Each of these steps isn’t usually described, they just form part of the whole ‘brushing teeth’ procedure. The next time you need to brush your teeth, you remember the ‘brushing teeth’ procedure and know exactly what to do.
Program code is easier to read and understand when it is broken up into smaller sections. By breaking a program up into these sections, or procedures, code can be made shorter and simpler.
When writing programs it is very easy to end up with long-winded, repetitive code which is hard to understand and debug. This is because the same task often needs to be carried out in different places in the program. Procedures can be used throughout a program, making them simpler and quicker to code.
Using procedures has an added benefit. If something needs to be changed in a procedure, it only needs to be changed once, within the procedure code. This change will then appear wherever the procedure is used in the program. If procedures weren’t used, the code would have to be amended at every point that it appears in the program.