Language Support
High-level programming languages usually include specific constructs to:
- delimit the part of the program (body) that makes up the subroutine
- assign an identifier (name) to the subroutine
- specify the names and/or data types of its parameters and/or return values
- provide a private naming scope for its temporary variables
- identify variables outside the subroutine that are accessible within it
- call the subroutine
- provide values to its parameters
- specify the return values from within its body
- return to the calling program
- dispose of the values returned by a call
- handle any exceptional conditions encountered during the call
- package subroutines into a module, library, object, class, etc.
Some programming languages, such as Visual Basic .NET, Pascal, Fortran, and Ada, distinguish between functions or function subprograms, which provide an explicit return value to the calling program, and subroutines or procedures, which do not. In those languages, function calls are normally embedded in expressions (e.g., a sqrt function may be called as y = z + sqrt(x)); whereas procedure calls behave syntactically as statements (e.g., a print procedure may be called as if x > 0 then print(x). Other languages, such as C and Lisp, do not make this distinction, and treat those terms as synonymous.
In strictly functional programming languages such as Haskell, subprograms can have no side effects, and will always return the same result if repeatedly called with the same arguments. Such languages typically only support functions, since subroutines that do not return a value have no use unless they can cause a side effect.
In programming languages such as C, C++, and C#, subroutines may also simply be called functions, not to be confused with mathematical functions or functional programming, which are different concepts.
A language's compiler will usually translate procedure calls and returns into machine instructions according to a well-defined calling convention, so that subroutines can be compiled separately from the programs that call them. The instruction sequences corresponding to call and return statements are called the procedure's prologue and epilogue.
Read more about this topic: Subroutine
Famous quotes containing the words language and/or support:
“I now thinke, Love is rather deafe, than blind,
For else it could not be,
That she,
Whom I adore so much, should so slight me,
And cast my love behind:
Im sure my language to her, was as sweet,
And every close did meet
In sentence, of as subtile feet,
As hath the youngest Hee,”
—Ben Jonson (15721637)
“Universal suffrage should rest upon universal education. To this end, liberal and permanent provision should be made for the support of free schools by the State governments, and, if need be, supplemented by legitimate aid from national authority.”
—Rutherford Birchard Hayes (18221893)