Subroutine
A named 'out of line' block of code that can be executed by simply writing its name in a program statement.
Procedures
Subroutines that perform actions but do not return a value.
Functions
Subroutines that perform actions and return a value.
Code Reusability
Writing code once and using it multiple times without rewriting.
Modularity
Breaking programs into manageable sections where each subroutine performs a specific task.
Simplified Maintenance
Easier updating and fixing of code with changes in a subroutine affecting all calls to it.
Improved Readability
Making code more organized and understandable by giving structure and clarity.
Enhanced Collaboration
Allowing different programmers to work on different subroutines simultaneously, particularly useful in large projects.
Parameters
Variables listed as part of a subroutine's definition to pass data into the subroutine.
By Value
Passing a copy of the data to the subroutine.
By Reference
Passing a reference to the actual data, allowing modifications.
Returning a Value
Subroutines can return a value to the calling routine using the return statement.
Local Variables
Variables declared within a subroutine, accessible only within that subroutine.
Encapsulation
Keeping variables confined to the subroutine to prevent interference with other parts of the program.
Memory Management
Local variables are automatically destroyed when the subroutine finishes execution.
Structured Approach
A method of programming that emphasizes breaking a program into smaller, manageable, and reusable modules or subroutines.
Modularization
Dividing the program into distinct subroutines.
Clear Interfaces
Using parameters and return values to define clear inputs and outputs for subroutines.
Documentation
Well-documented code with comments and clear variable names.
Improved Code Organization
Making large programs easier to understand and manage through a structured approach.
Enhanced Debugging and Testing
Easier testing of individual modules for improved debugging.
Facilitates Teamwork
Enabling different team members to work on separate modules simultaneously.
Scalability
Simplifying the process of adding new features or making changes.
Reuse of Code
Reusing subroutines in different parts of the program or in different programs.