What is procedures?
A procedure is a set of step‑by‑step instructions that tell a computer (or a person) how to do a specific task. In programming, it’s a block of code that you can name, write once, and run whenever you need that task performed. Think of it like a recipe: the ingredients are the inputs, the steps are the code, and the finished dish is the output.
Let's break it down
- Name - Every procedure has a unique name so you can call it later.
- Parameters (optional) - These are the inputs you give the procedure so it can work with different data each time.
- Body - The actual list of commands that get executed, one after another.
- Return value (optional) - After finishing, a procedure can send back a result to the part of the program that called it.
Why does it matter?
Procedures let you avoid repeating the same code over and over. By writing a task once and reusing it, you save time, reduce mistakes, and make your program easier to read and maintain. If you need to change how the task works, you only edit the procedure in one place and every part of the program that uses it gets the update automatically.
Where is it used?
- In almost every programming language (C, Java, Python, JavaScript, etc.)
- In databases as stored procedures that run on the server
- In operating systems for system calls and command‑line utilities
- In everyday software like spreadsheets (macros) and automation tools (Zapier, Power Automate)
Good things about it
- Reusability: Write once, use many times.
- Clarity: Gives a clear name to a chunk of logic, making code easier to understand.
- Maintainability: Fix bugs or add features in one spot instead of many.
- Modularity: Helps break a big program into smaller, manageable pieces.
- Testing: You can test a single procedure in isolation, improving reliability.
Not-so-good things
- Over‑abstraction: Too many tiny procedures can make the flow hard to follow.
- Performance overhead: Calling a procedure adds a small amount of extra work, which can matter in very tight loops.
- Scope confusion: If variables are not managed properly, you might get unexpected results or bugs.
- Dependency chains: Deeply nested procedure calls can make debugging more difficult.