FACTOID # 16: In the 2000 Presidential Election, Texas gave Ralph Nader the 3rd highest popular vote count of any US state.
 
 Home   Encyclopedia   Statistics   States A-Z   Flags   Maps   FAQ   About 
   
 
WHAT'S NEW
RELATED ARTICLES
People who viewed "Subroutine" also viewed:
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Subroutine

In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and can be relatively independent of the remaining code. The syntax of many programming languages includes support for creating self contained subroutines, and for calling and returning from them. Image File history File links Emblem-important. ... Computer science, or computing science, is the study of the theoretical foundations of information and computation and their implementation and application in computer systems. ... Source code (commonly just source or code) is any series of statements written in some human-readable computer programming language. ... A computer program is a collection of instructions that describe a task, or set of tasks, to be carried out by a computer. ... A task is an execution path through address space. In other words, a set of program instructions that is loaded in memory. ... For other uses, see Syntax (disambiguation). ... In computer programming, subprograms (functions) will return to the higher-level programs, which called them; return ends the current task. ...


There are many advantages to breaking a program up into subroutines, including:

The components of a subroutine may include: Duplicate code is a computer programming term for a sequence of source code that occurs more than once, either within a program or across different programs owned or maintained by the same entity. ... Graph of example function, The mathematical concept of a function expresses the intuitive idea of deterministic dependence between two quantities, one of which is viewed as primary (the independent variable, argument of the function, or its input) and the other as secondary (the value of the function, or output). A... Code reuse, also called software reuse, is the use of existing software, or software knowledge, to build new software. ... In computer science, decomposition, also known as factoring, refers to the process by which a complex problem or system is broken down into parts that are easier to conceive, understand, program, and maintain. ... Look up readability in Wiktionary, the free dictionary. ... In computer science, the principle of information hiding is the hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. ...

  • a body of code to be executed when the subroutine is called
  • parameters that are passed to the subroutine from the point where it is called
  • a value that is returned to the point where the call occurs

Many programming languages, such as Pascal , FORTRAN, Ada, distinguish between functions or function subprograms, which return values (via a return statement), and subroutines or procedures, which do not. Some languages, such as C and LISP, do not make this distinction, and treat those terms as synonymous. The name method is commonly used in connection with object-oriented programming, specifically for subroutines that are part of objects; it is also used in conjunction with type classes. In computer programming, a parameter is a variable which takes on the meaning of a corresponding argument passed in a call to a subroutine. ... Other listings of programming languages are: Categorical list of programming languages Generational list of programming languages Chronological list of programming languages Note: Esoteric programming languages have been moved to the separate List of esoteric programming languages. ... Pascal is a structured imperative computer programming language, developed in 1970 by Niklaus Wirth as a language particularly suitable for structured programming. ... Fortran (previously FORTRAN[1]) is a general-purpose[2], procedural,[3] imperative programming language that is especially suited to numeric computation and scientific computing. ... Ada is a structured, statically typed, imperative, and object-oriented high-level computer programming language. ... In computer programming, subprograms (functions) will return to the higher-level programs, which called them; return ends the current task. ... C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ... “LISP” redirects here. ... In object-oriented programming, the term method refers to a subroutine that is exclusively associated either with a class (called class methods, static methods, or factory methods) or with an object (called instance methods). ... Object-oriented programming (OOP) is a programming paradigm that uses objects and their interactions to design applications and computer programs. ... In strictly mathematical branches of computer science the term object is used in a purely mathematical sense to refer to any thing. While this interpretation is useful in the discussion of abstract theory, it is not concrete enough to serve as a primitive datatype in the discussion of more concrete... The type system of the Haskell programming language includes a construct called the type class that provides a powerful form of restricted parametric polymorphism. ...


Maurice Wilkes, Stanley Gill, and David Wheeler are credited with the invention of the subroutine (which they referred to as the closed subroutine).[citation needed] Maurice V. Wilkes Maurice Vincent Wilkes (born June 26, 1913 in Dudley, Staffordshire, England) is a British computer scientist, credited with several important developments in computing. ... Professor Stanley Gill (1926 - 1975) was a British computer scientist credited, along with Maurice Wilkes and David Wheeler, with the invention of the first computer subroutine. ... David John Wheeler FRS (9 February 1927 – 13 December 2004) was a computer scientist. ...

Contents

Early history

The first use of subprograms was on early computers that were programmed in machine code or assembly language, and did not support a call instruction. On these computers, subroutines had to be called by a sequence of lower level machine instructions, possibly implemented as a macro. These instructions typically modified the program code, modifying the address of a branch at a standard location so that it behaved like an explicit return instruction. Even with this cumbersome approach subroutines proved very useful. The available memory on early computers was many orders of magnitude smaller than that available on today's computers, and non-trivial subroutines saved memory by reducing redundancy. Soon, most architectures provided instructions to help with subroutine calls, leading to explicit call instructions. Machine code or machine language is a system of instructions and data directly understandable by a computers central processing unit. ... See the terminology section, below, regarding inconsistent use of the terms assembly and assembler. ... For other uses, see Macro (disambiguation) A macro in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to an output sequence (also often a sequence of characters) according to a defined procedure. ... An order of magnitude is the class of scale or magnitude of any amount, where each class contains values of a fixed ratio to the class preceding it. ...


Technical overview

A subprogram, as its name suggests, behaves in much the same way as a complete computer program, but on a smaller scale. Typically, the caller waits for subprograms to finish and continues execution only after a subprogram "returns". Subroutines are often given parameters to refine their behavior or to perform a certain computation with given values. In computer programming, subprograms (functions) will return to the higher-level programs, which called them; return ends the current task. ... In computer programming, a parameter is a variable which takes on the meaning of a corresponding argument passed in a call to a subroutine. ...


No Stack

Early FORTRAN compilers were written for machines like the HP 2100 which did not support stacks (or recursion) with hardware stack registers. The Jump to subroutine instruction had the following format: Hewlett-Packards first computer, the 2116A of the HP-2100 series, was developed in the late 1960s. ... A stack register is a register of a computer central processor whose purpose is to keep track of a call stack. ...

 ------+-----+---------+-------- label JSB m[,I] comments 

The address for label is placed into the location represented by m and control transfers to the NEXT location, m+1. On completion of the subroutine, control may be returned to the normal sequence by performing a JMP m,I. This reserves a location at or before the start of a subroutine to save the return location. This did not require a separate stack, but did not support recursion since there is only one return storage location per subroutine. A similar technique was used by Lotus 1-2-3 to support a tree walk to compute recalculation dependencies, as a location was reserved in each cell to store the "return" address. Since circular references are not allowed for natural recalculation order, this allows a tree walk without reserving space for a stack in memory which was very limited on small computers such as the IBM PC. Lotus 1-2-3 is a spreadsheet program from Lotus Software (now part of IBM). ... IBM PC (IBM 5150) with keyboard and green screen monochrome monitor (IBM 5151), running MS-DOS 5. ...


Stack

Most implementations use a call stack to implement subroutine calls and returns. In computer science, a call stack is a special stack which stores information about the active subroutines of a computer program. ...


When an assembly language program executes a call, program flow jumps to another location, but the address of the next instruction (that is, the instruction that follows the call instruction in memory) is kept somewhere to use when returning. The IBM System/360 saved this address in a processor register, relying on convention to save and restore registers and return addresses in memory associated with individual subroutines, then using branches to the address specified in the register to accomplish a subroutine return. System/360 Model 65 operators console, with register value lamps and toggle switches (middle of picture) and emergency pull switch (upper right). ... In computer architecture, a processor register is a small amount of very fast computer memory used to speed the execution of computer programs by providing quick access to frequently used values—typically, these values are involved in multiple expression evaluations occurring within a small region on the program. ... In both conventional and electronic messaging, a return address is an explicit inclusion of the address of the person sending the message. ... In computer programming, subprograms (functions) will return to the higher-level programs, which called them; return ends the current task. ...


Compilers for most languages use a push-down stacks and support recursive subroutine calls (each call is given a fresh new location to store the return address). In a stack based architecture, the return address is 'pushed' as a point of return on the stack. The subroutine 'returns' by 'popping' a return value from the top of the stack, which reads the previously pushed return address and jumps to it, so that program flow continues immediately after the call instruction. Most RISC and VLIW architectures save the return address in a link register (as the IBM 360 did), but simulate a stack with load and store instructions rather than with push and pop instructions. The disadvantage of such a scheme is that the stack can overflow if recursion takes place at too many levels, or if the variables on each stack frame are too large. If there is not sufficient stack space, and there is no recursion, a tree-walk can be simulated with an iterative algorithm, storing return locations at each tree node, as was done with Lotus 1-2-3 and work-alike clone, The Twin which were based on PC's with very limited stack space. Simple representation of a stack In computer science, a stack is a temporary abstract data type and data structure based on the principle of Last In First Out (LIFO). ... This article is about the concept of recursion. ... Reduced Instruction Set Computer (RISC), is a microprocessor CPU design philosophy that favors a smaller and simpler set of instructions that all take about the same amount of time to execute. ... A very long instruction word or VLIW CPU architectures implement a form of instruction level parallelism. ... A link register, in many CPU architectures such as the PowerPC, ARM, and the PA-RISC, is a special purpose register which holds the address to return to when a function call completes. ... Lotus 1-2-3 is a spreadsheet program from Lotus Software (now part of IBM). ...


This section deals with the modern implementation of having subroutine data stored on one or more stacks.


Due to usage of a stack, a subroutine can call itself (see recursion) or other subroutines (nested calls), and of course it can call the same subroutine from several distinct places. Assembly languages generally do not provide programmers with such conveniences as local variables or subroutine parameters. They get to be implemented by passing values in registers or pushing them onto the stack (or another stack, if there is more than one). This article is about the concept of recursion. ...


When there is just one stack, the return addresses must be placed in the same space as the parameters and local variables. Hence, a typical stack may look like this (for a case where function1 calls function2): In computer programming, a parameter is a variable which takes on the meaning of a corresponding argument passed in a call to a subroutine. ... In computer science, a local variable is a variable that is given local scope. ...

  • Previous stack data
  • Function1 local variables
  • Parameters for function2
  • Function1 return address (of the instruction which called function2)
  • Function2 local variables

This is with a forwards-growing stack — on many architectures the stack grows backwards in memory. Forward and backwards-growing stacks are useful because it is quite practical to have two stacks growing towards each other in a common scratch space, using one mainly for control information like return addresses and loop counters and the other for data. (This is what Forth does.) Forth is a programming language and programming environment, initially developed by Charles H. Moore at the US National Radio Astronomy Observatory in the early 1970s. ...


The parts of the program which are responsible for the entry into and exit out of the subroutine (and hence, the setting up and removal of each stack frame) are called the function prologue and epilogue. In assembly language programming, the function prologue is a few lines of code which appear at the beginning of a function, which prepare the stack and registers for use within the function. ...


If the procedure or function itself uses stack handling commands, outside of the prologue and epilogue, e.g. to store intermediate calculation values, the programmer needs to keep track of the number of 'push' and 'pop' instructions so as not to corrupt the original return address.


Side-effects

In most imperative programming languages, subprograms may have so-called side-effects; that is, they may cause changes that remain after the subprogram has returned. It can be technically very difficult to predict whether a subprogram has a side-effect or not. In imperative programming, compilers usually assume every subprogram has a side-effect to avoid complex analysis of execution paths. Because of its side-effects, a subprogram may return different results each time it is called, even if it is called with the same arguments. A simple example is a subprogram that implements a pseudorandom number generator; that is, a subprogram that returns a random number each time it is called. In computer science, imperative programming, as opposed to declarative programming, is a programming paradigm that describes computation in terms of a program state and statements that change the program state. ... In computer science, a side-effect is a property of a programming language function that it modifies some state other than its return value. ... A diagram of the operation of a typical multi-language, multi-target compiler. ... In computer programming, a parameter is a variable which takes on the meaning of a corresponding argument passed in a call to a subroutine. ... A pseudorandom number generator (PRNG) is an algorithm to generate a sequence of numbers that approximate the properties of random numbers. ...


In pure 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 have only functions, since subroutines that do not return a value are useless if they cannot have any other effect either. In functional programming writing to a file is also a side effect. Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. ... Haskell is a standardized purely functional programming language with non-strict semantics, named after the logician Haskell Curry. ...


C and C++ examples

In the C and C++ programming languages, subprograms are referred to as "functions" (or "methods" when associated with a class). Note that these languages use the special keyword void to indicate that a function takes no parameters (especially in C) and/or does not return any value. Note that C/C++ functions can have side-effects, including modifying any variables whose addresses are passed as parameters (i.e. "passed by reference"). Examples: C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ... C++ (pronounced see plus plus, IPA: ) is a general-purpose programming language with high-level and low-level capabilities. ... In object-oriented programming, a class is a programming language construct used to group related fields and methods. ...

 void function1(void) { /* some code */ } 

The function does not return a value and has to be called as a stand-alone function, e.g., function1();

 int function2(void) { return 5; } 

This function returns a result (the number 5), and the call can be part of an expression, e.g., x + function2()

 char function3 (int number) { char selection[] = {'S','M','T','W','T','F','S'}; return selection[number]; } 

This function converts a number between 0 to 6 into the initial letter of the corresponding day of the week, namely 0 → 'S', 1 → 'M', ..., 6 → 'S'. The result of calling it might be assigned to a variable, e.g., num_day = function3(number);.

 void function4 (int* pointer_to_var) { (*pointer_to_var)++; } 

This function does not return a value but modifies the variable whose address is passed as the parameter; it would be called with "function4(&variable_to_increment);".


Local variables, recursion and re-entrancy

A subprogram may find it useful to make use of a certain amount of "scratch" space; that is, memory used during the execution of that subprogram to hold intermediate results. Variables stored in this scratch space are referred to as local variables, and the scratch space itself is referred to as an activation record. An activation record typically has a return address that tells it where to pass control back to when the subprogram finishes. In both conventional and electronic messaging, a return address is an explicit inclusion of the address of the person sending the message. ...


A subprogram may have any number and nature of call sites. If recursion is supported, a subprogram may even call itself, causing its execution to suspend while another nested execution of the same subprogram occurs. Recursion is a useful technique for simplifying some complex algorithms, and breaking down complex problems. Recursive languages generally provide a new copy of local variables on each call. If the programmer desires the value of local variables to stay the same between calls, they can be declared "static" in some languages, or global values or common areas can be used. This article is about the concept of recursion. ...


Early languages like Fortran did not initially support recursion because variables were statically allocated, as well as the location for the return address. Most computers before the late 1960s such as the PDP-8 did not have support for hardware stack registers. Fortran (previously FORTRAN[1]) is a general-purpose[2], procedural,[3] imperative programming language that is especially suited to numeric computation and scientific computing. ... A PDP-8 on display at the Smithsonians National Museum of American History in Washington, D.C.. This example is from the first generation of PDP-8s, built with discrete transistors and later known as the Straight 8. ...


Modern languages after ALGOL such as Pl/1 and C almost invariably use a stack, usually supported most modern computer instruction sets to provide a fresh activation record for every execution of a subprogram. That way, the nested execution is free to modify its local variables without concern for the effect on other suspended executions in progress. As nested calls accumulate, a call stack structure is formed, consisting of one activation record for each suspended subprogram. In fact, this stack structure is virtually ubiquitous, and so activation records are commonly referred to as stack frames. In computer science, a call stack is a special stack which stores information about the active subroutines of a computer program. ... In computing, a stack frame is a data structure used to create temporary storage for data and saved state in functions. ...


Some languages such as Pascal and Ada also support nested subroutines, which are subroutines callable only within the scope of an outer (parent) subroutine. Inner subroutines have access to the local variables of the outer subroutine which called them. This is accomplished by storing extra context information within the activation record, also known as a display. A nested function is a function which can only be called from its parent function. ... In computer programming, scope is an enclosing context where values and expressions are associated. ...


If a subprogram can function properly even when called while another execution is already in progress, that subprogram is said to be re-entrant. A recursive subprogram must be re-entrant. Re-entrant subprograms are also useful in multi-threaded situations, since multiple threads can call the same subprogram without fear of interfering with each other. A computer program or routine is described as reentrant if it is designed in such a way that a single copy of the programs instructions in memory can be shared by multiple users or separate processes. ... For the form of code consisting entirely of subroutine calls, see Threaded code. ...


In a multi-threaded environment, there is generally more than one stack. An environment which fully supports coroutines or lazy evaluation may use data structures other than stacks to store their activation records. For the form of code consisting entirely of subroutine calls, see Threaded code. ... In computer science, coroutines are program components that generalize subroutines to allow multiple entry points and suspending and resuming of execution at certain locations. ... In computer programming, lazy evaluation is a technique that attempts to delay computation of expressions until the results of the computation are known to be needed. ...


Overloading

Sometimes, it is desirable to have one function to be able to take in different series of parameters. When a function with the same name can accept different parameters, it is said to be overloaded. For example, a subroutine might construct an object that will accept directions, and trace its path to these points on screen. There are a plethora of parameters that could be passed in to the constructor (colour of the trace, starting x and y co-ordinates, trace speed). If the programmer wanted the constructor to be able to accept only the color parameter, then he could call another constructor that accepts only color, which in turn calls the constructor with all the parameters passing in a set of "default values" for all the other parameters (X and Y would generally be centered on screen or placed at the origin, and the speed would be set to another value of the coder's choosing). In computer programming, operator overloading (less commonly known as operator ad-hoc polymorphism) is a specific case of polymorphism in which some or all of operators like +, = or == have different implementations depending on the types of their arguments. ...


Conventions

A number of conventions for the coding of subprograms have been developed. It has been commonly preferable that the name of a subprogram should be a verb when it does a certain task, an adjective when it makes some inquiry, and a noun when it is used to substitute variables and such.


Experienced programmers recommend that a subprogram perform only one task. If a subprogram performs more than one task, it should be split up into more subprograms. They argue that subprograms are key components in maintaining code and their roles in the program must be distinct.


Some advocate that each subprogram should have minimal dependency on other pieces of code. For example, they see the use of global variables as unwise because it adds tight-coupling between subprograms and global variables. If such coupling is not necessary at all, they advise to refactor subprograms to take parameters instead. This practice is controversial because it tends to increase the number of passed parameters to subprograms. In computer programming, a global variable is a variable that is accessible in every scope. ...


Efficiency and inlining

There is a runtime overhead associated with passing parameters, calling the subprogram, and returning. The actual overhead for each invocation depends on the local context at the point of call and the requirements specified in the architecture's ABI. Abigail, meaning Fathers Joy, in Hebrew, is a popular name. ...


One technique used to minimise this overhead is inline expansion of the subprogram call site. However, inlining often increases code size and can introduce cache misses into a previously optimised block of code. In-line expansion or inlining for short is a compiler optimization which expands a function call site into the actual implementation of the function which is called, rather than each call transferring control to a common piece of code. ... In programming, a call site of a function is a place where the function is, or may be (by virtue of dynamic dispatch) called. ... This article is about the computer term. ...


Dynamic dispatch can introduce further overheads - although the performance difference between indirect and direct calls on commodity CPUs has narrowed since the 1980s, because of research and work done by CPU designers (driven by the increasing popularity of object-oriented programming, which uses dynamic dispatch extensively). Also, software techniques have been developed to make dynamic dispatch more efficient. In computer science, dynamic dispatch is the process of mapping a message to a specific sequence of code (method) at runtime. ... Year 1980 (MCMLXXX) was a leap year starting on Tuesday (link displays the 1980 Gregorian calendar). ...


Related terms and clarification

Different programming languages and methodologies possess notions and mechanisms related to subprograms:

  • Subroutine is practically synonymous with "subprogram." The former term may derive from the terminology of assembly languages and Fortran.
  • Function and Procedure are also synonymous with "subprogram" - with the distinction (in some programming languages) that "functions", generate return values and appear in expressions, where "procedures", generate no return values and appear in statements. Hence, a subprogram that calculates the square root of a number would be a "function" (eg: y = sqrt(x);) where a subprogram to print out a number might be a "procedure" (eg: print(x);). This is not a distinction found in all programming languages and notably the C family of programming languages use the two terms interchangeably. See also: Command-Query Separation.
  • Predicate is, in general, a boolean-valued function (a function that returns a boolean). In logic programming languages, often all subroutines are called "predicates", since they primarily determine success or failure.
  • Method or Member function is a special kind of subprogram used in object-oriented programming that describes some behaviour of an object.
  • Closure is a subprogram together with the values of some of its variables captured from the environment in which it was created.
  • Coroutine is a subprogram that returns to its caller before completing.
  • Event handler, or simply "handler," is a subprogram that is called in response to an "event", such as a computer user moving the mouse or typing on the keyboard. The AppleScript scripting language simply uses the term "handler" as a synonym for subprogram. Event handlers are often used to respond to an Interrupt - in which case they may be termed an Interrupt handler.
  • Threaded code makes code even more compact. It uses a small interpreter to execute subroutines that consist of lists of subroutine addresses. The lowest levels of subroutine are the only machine language.

See the terminology section, below, regarding inconsistent use of the terms assembly and assembler. ... Fortran (also FORTRAN) is a statically typed, compiled, programming language originally developed in the 1950s and still heavily used for scientific computing and numerical computation half a century later. ... An expression in a programming language is a combination of values and functions or procedures, interpreted according to the particular rules of precedence and of association for a particular programming language, which computes and then returns another value. ... A statement is the minimal unit of structuring in imperative programming languages. ... Command-query separation (CQS) is a principle of object-oriented computer programming. ... A boolean-valued function, in some usages a predicate or a proposition, is a function of the type f : X → B, where X is an arbitrary set and where B is a boolean domain. ... Logic programming (which might better be called logical programming by analogy with mathematical programming and linear programming) is, in its broadest sense, the use of mathematical logic for computer programming. ... In object-oriented programming, the term method refers to a subroutine that is exclusively associated either with a class (called class methods, static methods, or factory methods) or with an object (called instance methods). ... Object-oriented programming (OOP) is a programming paradigm that uses objects and their interactions to design applications and computer programs. ... In strictly mathematical branches of computer science the term object is used in a purely mathematical sense to refer to any thing. While this interpretation is useful in the discussion of abstract theory, it is not concrete enough to serve as a primitive datatype in the discussion of more concrete... In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. ... In computer science, coroutines are program components that generalize subroutines to allow multiple entry points and suspending and resuming of execution at certain locations. ... An event handler is a part of a computer program created to tell the program how to act in response to a specific event (e. ... AppleScript is a scripting language devised by Apple, Inc. ... In computing, an interrupt is an asynchronous signal from hardware or software indicating the need for attention. ... In computer science, the term threaded code refers to an implementation technique for programming languages that produces very compact code. ... In computer science, an interpreter is a computer program that executes, or performs, instructions written in a computer programming language. ...

See also

Look up subroutine in Wiktionary, the free dictionary.

Wikipedia does not have an article with this exact name. ... Wiktionary (a portmanteau of wiki and dictionary) is a multilingual, Web-based project to create a free content dictionary, available in over 150 languages. ... Graph of example function, The mathematical concept of a function expresses the intuitive idea of deterministic dependence between two quantities, one of which is viewed as primary (the independent variable, argument of the function, or its input) and the other as secondary (the value of the function, or output). A... In object-oriented programming, the term method refers to a subroutine that is exclusively associated either with a class (called class methods, static methods, or factory methods) or with an object (called instance methods). ... It has been suggested that this article or section be merged into Modularity (programming). ... In computer science, some hypertext systems, including Ted Nelsons Xanadu Project, have the capability for documents to include sections of other documents by reference, called transclusion. ...

References

  • Wilkes, M. V.; Wheeler, D. J., Gill, S. (1951). Preparation of Programs for an Electronic Digital Computer. Addison-Wesley. 

  Results from FactBites:
 
Subroutine - Wikipedia, the free encyclopedia (1993 words)
In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code.
Subroutines are often given parameters to refine their behavior or to perform a certain computation with given [variable] values.
Subroutine is practically synonymous with "subprogram." The former term may derive from the terminology of assembly languages and Fortran.
Perl Subroutine Primer (1/2) (2349 words)
When you define and use subroutines, the code logic is neatly contained in a single location of the script and can be called (and later modified, when necessary) without requiring you to track down every instance of the logic in the script at large.
Subroutines in Perl are easy to define and use; but like practically any other aspect of any programming language, there are some rules that you need to know --and follow-- to make the most of them (and avoid shooting yourself in the foot).
While some subroutines may be helpful as static code blocks (that simply repeat the exact same action as needed without any variation) most subroutines become more useful by passing parameters--sending variable values to the subroutine that it should act on, and possibly receiving unique values back from the subroutine in response.
  More results at FactBites »

 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m