zaro

What is a Computer Procedure?

Published in Programming Concepts 2 mins read

A computer procedure is a section of computer code that performs a specific task.

In programming, a procedure is a small, self-contained block of code within a larger program. Think of it as a mini-program designed to do one particular job.

Based on the reference:

  • A procedure is a small section of a program.
  • Its main purpose is to perform a specific task.

These sections are often given a name, and they can be called upon, or "executed," whenever that specific task needs to be done within the program.

Why Use Procedures?

Procedures are fundamental building blocks in programming for several important reasons:

  • Reusability: As the reference states, procedures can be used repeatedly throughout a program. Instead of writing the same lines of code multiple times, you write them once in a procedure and call that procedure whenever needed.
  • Organization: They break down complex programs into smaller, more manageable parts, making the code easier to understand, write, and debug.
  • Readability: Giving a procedure a descriptive name helps explain what a section of code does, improving the clarity of the program.
  • Maintainability: If you need to change how a specific task is performed, you only need to modify the code inside the procedure, rather than searching for and changing duplicate code throughout the entire program.

Procedure vs. Function (Quick Note)

While often used interchangeably or having subtle differences depending on the programming language, a common distinction is that a function typically performs a task and returns a result (a value), whereas a procedure primarily performs a task without necessarily returning a specific value. However, the core concept of a named block of code performing a specific task remains similar.

Real-Life Analogy

The reference provides a helpful real-life example:

  • A real-life example of a procedure is brushing your teeth.

Consider the steps involved in brushing your teeth: applying toothpaste, brushing each section of your mouth, rinsing, etc. These are all steps performed in sequence to achieve the specific task of cleaning your teeth. You perform this procedure repeatedly (usually daily).

In programming, a procedure might be something like "save_user_data," "calculate_total_cost," or "print_report." Each performs a distinct, specific task within the larger software application.