Function (computer programming): Difference between revisions

Content deleted Content added
m Disambiguating links to Pearson (link changed to Pearson PLC) using DisamAssist.
Meownium (talk | contribs)
Modify tone
Line 4:
{{anchor|SUBROUTINE_DEFINITION}}
 
In [[computer programming]], a '''function''', '''subprogram''', '''procedure''', '''method''', or '''routine''' or(also known as a '''subroutinesubprogram''') is a '''callable unit'''<ref>{{cite web
|title=Terminology Glossary
|url=https://pages.nist.gov/ElectionGlossary/
Line 18:
==Terminology==
 
The meaning of each callable term, function, subprogram, procedure, method, routine and subroutineroutine, is, in fact different. They are not [[synonymous]]. None-the-lessNevertheless, they each add a capability to programming that has commonality.
 
The term used tends to reflect the context in which it is used {{endash}} usually based on the language being used. For exmapleexample:
 
* The terms ''routine,'' ''subroutine, or subprogram'' refer to the same meaning, but describe a hierarchical relationship, much like how a subdirectory is structurally subordinate to it's parent directory.
* ''Subprogram'' was used long ago but today is antiquated
 
* Some consider ''function'' to imply a [[Function (mathematics)|mathematical function;]], acting upon the given inputs to return an output with no side-effects, but in many contexts (languages)a ''function'' doessimply refers to another callable section notwithin implythe thatprogram.
* The terms ''routine'' and ''subroutine'' (both antiquated) describe the same thing, but highlight a [[subordinate]] calling relationship that is similar to how a ''subdirectory'' is structurally subordinate to a ''[[Directory (computing)|directory]]'' {{endash}} a subdirectory is a directory and (except for the root) a directory is a subdirectory.
 
* In the context of [[Visual Basic]], {{code|Sub}}, short for ''subroutine'' or ''subprocedure'', is the name of a callable that does not return a value whereas a {{code|Function}} does return a value -- much like [[Ada (programming language)|Ada]].
* Some consider ''function'' to imply mathematical function; no side-effects, but in many contexts (languages) ''function'' does not imply that
 
* [[C (programming language)|C]] and [[C++]] have ''functions'', butLanguages relatedsuch languagesas [[C#]] and [[Java (programming language)|Java]] use the wordterm ''method'' forto whatrefer is essentiallyto a member function that is a member of an [[Object (computer science)|object]], and may act on behalf of the object.
* In the context of [[Visual Basic]], {{code|Sub}}, short for ''subroutine'' or ''subprocedure'', is the name of a callable that does not return a value whereas a {{code|Function}} does return a value
 
* [[C (programming language)|C]] and [[C++]] have ''functions'', but related languages [[C#]] and [[Java (programming language)|Java]] use the word ''method'' for what is essentially a function that is a member of an [[Object (computer science)|object]]
 
==History==
 
The idea of a callable unit was initially conceived by [[John Mauchly]] and [[Kathleen Antonelli]] during their work on [[ENIAC]] and recorded in a January 1947 Harvard symposium on "Preparation of Problems for [[EDVAC]]-type Machines"."<ref name=mauchly0>{{cite book|first=J.W.|last=Mauchly|chapter=Preparation of Problems for EDVAC-Type Machines |author-link=John Mauchly|editor-first=Brian|editor-last=Randell|title=The Origins of Digital Computers|doi=10.1007/978-3-642-61812-3_31|publisher=Springer|date=1982|pages=393–397 |isbn=978-3-642-61814-7 }}</ref> [[Maurice Wilkes]], [[David Wheeler (British computer scientist)|David Wheeler]], and [[Stanley Gill]] are generally credited with the formal invention of this concept, which they termed a ''closed sub-routine'',<ref>{{Cite conference |last1 = Wheeler |first1 = D. J. |author-link1 = David Wheeler (computer scientist) |chapter = The use of sub-routines in programmes |doi = 10.1145/609784.609816 |title = Proceedings of the 1952 ACM national meeting (Pittsburgh) on - ACM '52 |pages = 235 |year = 1952 |chapter-url = http://www.laputan.org/pub/papers/wheeler.pdf|doi-access = free }}</ref><ref>{{cite book |last1= Wilkes |first1= M. V. |last2= Wheeler |first2= D. J. |last3= Gill |first3=S. |title= Preparation of Programs for an Electronic Digital Computer |publisher= Addison-Wesley |year= 1951}}</ref> contrasted with an ''open subroutine'' or [[Macro (computer science)|macro]].<ref>{{cite encyclopedia |last=Dainith |first=John |title="open subroutine." A Dictionary of Computing | date=2004 |url=http://www.encyclopedia.com/doc/1O11-opensubroutine.html |encyclopedia=Encyclopedia.com |access-date=January 14, 2013}}</ref> However, [[Alan Turing]] had discussed subroutines in a paper of 1945 on design proposals for the NPL [[Automatic Computing Engine|ACE]], going so far as to invent the concept of a [[Call stack|return address stack]].<ref>{{Citation | last = Turing | first =Alan M. | author-link = Alan Turing | title = Report by Dr. A.M. Turing on proposals for the development of an Automatic Computing Engine (ACE): Submitted to the Executive Committee of the NPL in February 1946 | year = 1945 }} reprinted in {{Cite book | editor-last = Copeland | editor-first = B. J. | editor-link = Jack Copeland | title = Alan Turing's Automatic Computing Engine | ___location = Oxford | publisher = Oxford University Press | publication-date = 2005 | isbn = 0-19-856593-3 | year = 2005 | url-access = registration | url = https://archive.org/details/alanturingsautom0000unse |page=383}}</ref>
 
The idea of a subroutine was worked out after computing machines had already existed for some time. The arithmetic and conditional jump instructions were planned ahead of time and have changed relatively little, but the special instructions used for procedure calls have changed greatly over the years. The earliest computers and microprocessors, such as the [[Manchester Baby]] and the [[RCA 1802]], did not have a single subroutine call instruction. Subroutines could be implemented, but they required programmers to use the call sequence—a series of instructions—at each [[call site]].