In computer science, a subroutine, also termed procedure, function, routine, method, or subprogram, is a part of source code within a larger computer program that performs a specific task and is relatively independent of the remaining code.
As the name subprogram suggests, a subroutine behaves in much the same way as a computer program that is used as one step in a larger program or another subprogram. A subroutine is often coded so that it can be started (called) several times and/or from several places during one execution of the program, including from other subroutines, and then branch back (return) to the next instruction after the call once the subroutine's task is done.
Maurice Wilkes, David Wheeler, and Stanley Gill are credited with the invention of this concept, which they termed a closed subroutine.
Subroutines are a powerful programming tool, and the syntax of many programming languages includes support for writing and using them. Judicious use of subroutines (for example, through the structured programming approach) will often substantially reduce the cost of developing and maintaining a large program, while increasing its quality and reliability. Subroutines, often collected into libraries, are an important mechanism for sharing and trading software. The discipline of object-oriented programming is based on objects and methods (which are subroutines attached to these objects or object classes).
In the compiling method called threaded code, the executable program is basically a sequence of subroutine calls.
Read more about Subroutine: Main Concepts, Language Support, Advantages, Disadvantages, C and C++ Examples, Visual Basic 6 Examples, Local Variables, Recursion and Reentrancy, Overloading, Closures, Conventions, Optimization of Subroutine Calls, Related Terms and Clarification
Other articles related to "subroutine, subroutines":
... In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine ... An ordered list of parameters is usually included in the definition of a subroutine, so that, each time the subroutine is called, its arguments for that call can be ... In the most common case, call-by-value, a parameter acts within the subroutine as a local (isolated) copy of the argument, but in other cases, e.g ...
... int brk(void *end_data_segment) void *sbrk(intptr_t increment) The brk subroutine sets the program break value to the value of the end_data_segment parameter and changes the ... The sbrk subroutine adds to the program break value the number of bytes contained in the increment parameter and changes the amount of available space accordingly ... Upon successful completion, the brk subroutine returns a value of 0, and the sbrk subroutine returns the prior value of the program break (if the available space is increased, then the return ...
... The name subroutine was prevalent in assembly languages and Fortran ... A subroutine is sometimes called a callable unit ...
... is analogous to a source file in C (in that the subroutines and functions relevant to a particular task/category are grouped together, for instance) and consists of lines of MUMPS code ... Line labels can be used to create memory resident subroutines within the routine by starting the line with a label instead of whitespace ... The same subroutine can be used from outside the parent routine's scope by referencing the label and routine name separated by a caret character (as in SUBRTN^ABC) ...
... All subroutines are given numbers when they are defined and these numbers are used in the CALL to identify them ... If, for example, a LAYER statement and a BOX statement are packaged into subroutine 4, then the statement C 4 will cause the box to be drawn on that layer ... In addition to simply invoking the subroutine, a CALL statement can include transformations to affect the geometry inside the subroutine ...