Procedure: A type of subroutine that does not return a value

A detailed exploration of the concept of Procedure in programming, which is a type of subroutine that does not return a value.

A Procedure in programming is a type of subroutine that performs a specific task or a set of tasks but does not return a value. Unlike functions that typically return a value to the calling environment, procedures execute their operations silently without providing direct feedback through a return value.

Types of Procedures

Parameterized Procedures

Parameterized Procedures take arguments or parameters, which are inputs that alter the behavior or outcome of the procedure. For example:

1def greeting(name):
2    print(f"Hello, {name}!")

Non-Parameterized Procedures

Non-Parameterized Procedures do not take any inputs and perform their task independently. For example:

1def display_current_time():
2    print(time.ctime())

Special Considerations

State and Side Effects

Procedures can change the state of the program or have side effects, such as modifying global variables, altering data structures, or interacting with I/O devices. These changes are performed through their internal logic.

Examples of Procedures

Example in Python

1def save_to_file(data, filename="default.txt"):
2    with open(filename, 'w') as file:
3        file.write(data)

This procedure writes the provided data to a file, but it does not return a value.

Historical Context

The concept of procedures in programming dates back to early procedural programming languages like FORTRAN and COBOL, which emphasized the breakdown of large tasks into smaller, manageable subprograms for easier development and maintenance.

Applicability

Procedures are used across various programming paradigms to encapsulate behavior:

Comparisons

Procedures vs Functions

  • Procedures:

    • Do not return a value.
    • Can have side effects.
  • Functions:

    • Return a value.
    • Are often used to compute and return data without side effects (pure functions).
  • Function: A subroutine that returns a value.
  • Method: A procedure or function that belongs to an object or class.
  • Subroutine: A general term for procedures and functions.
  • Lambda: An anonymous function, often used for short snippets of code without a name.

FAQs

Can a procedure return a value?

No, by definition, a procedure does not return a value. If a subroutine returns a value, it is typically called a function.

Why use a procedure over a function?

Procedures are useful for tasks that require executing commands without the need to return a result. They can simplify code by separating process and outcome.

Are procedures used in modern programming languages?

Yes, procedures are used in many modern languages such as Python, JavaScript, C++, and more, often in the context of methods within objects or classes.

References

  • Richards, J., & Ryan, J. (1970). FORTRAN IV Programming. McGraw-Hill.
  • Sebesta, R. W. (2016). Concepts of Programming Languages. 11th Edition. Pearson.

Summary

Procedures are fundamental constructs in programming, enabling developers to encapsulate and organize code that performs specific tasks without returning a value. They have historical significance in the evolution of programming languages and remain pertinent in modern software development for managing side effects and state changes. Understanding procedures allows for better code modularity, readability, and maintenance.

By comprehending the role and characteristics of procedures, programmers can effectively utilize them to streamline processes and workflows within their applications.

Finance Dictionary Pro

Our mission is to empower you with the tools and knowledge you need to make informed decisions, understand intricate financial concepts, and stay ahead in an ever-evolving market.