Function (computer programming)

Sequence of program instructions packaged as a unit / From Wikipedia, the free encyclopedia

Dear Wikiwand AI, let's keep it short by simply answering these key questions:

Can you list the top facts and stats about Algorithm function?

Summarize this article for a 10 years old


In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.

Functions may be defined within programs, or separately in libraries that can be used by many programs. In different programming languages, a function may be called a routine, subprogram, subroutine, method, or procedure. Technically, these terms all have different definitions, and the nomenclature varies from language to language. The generic umbrella term callable unit is sometimes used.[1]

A function is often coded so that it can be started several times and from several places during one execution of the program, including from other functions, and then branch back (return) to the next instruction after the call, once the function's task is done.

The idea of a subroutine was initially conceived by John Mauchly and Kathleen Antonelli during their work on ENIAC,[2] and recorded in a January 1947 Harvard symposium on "Preparation of Problems for EDVAC-type Machines".[3] Maurice Wilkes, David Wheeler, and Stanley Gill are generally credited with the formal invention of this concept, which they termed a closed sub-routine,[4][5] contrasted with an open subroutine or macro.[6] However, Alan Turing had discussed subroutines in a paper of 1945 on design proposals for the NPL ACE, going so far as to invent the concept of a return address stack.[7]

Functions are a powerful programming tool,[8] and the syntax of many programming languages includes support for writing and using subroutines. Judicious use of functions (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.[9] Functions, 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 functions attached to these objects or object classes).