Imperative programming: Difference between revisions

Content deleted Content added
Undid revision 1121515508 by 27.2.20.10 (talk)
Fortran: expanding w/ citation
Line 1:
{{Short description|Type of programming paradigm in computer science}}
{{more citations needed|date=October 2011}}
{{Programming paradigms}}In [[computer science]], '''imperative programming''' is a [[programming paradigm]] of [[software]] that uses [[Statement (computer science)|statement]]s that change a program's [[state (computer science)|state]]. In much the same way that the [[imperative mood]] in [[natural language]]s expresses commands, an imperative program consists of [[command (computing)|command]]s for the [[computer]] to perform. Imperative programming focuses on describing ''how'' a program operates step by step,<ref>{{Cite web |last=Jain |first=Anisha |date=2022-12-10 |title=Javascript Promises— Is There a Better Approach? |url=https://medium.datadriveninvestor.com/javascript-promises-is-there-a-better-approach-dd6a0a329131 |access-date=2022-12-20 |website=Medium |language=en}}</ref> rather than on high-level descriptions of its expected results.
 
The term is often used in contrast to [[declarative programming]], which focuses on ''what'' the program should accomplish without specifying all the details of ''how'' the program should achieve the result.<ref>{{Cite web |title=Imperative programming: Overview of the oldest programming paradigm |url=https://www.ionos.com/digitalguide/websites/web-development/imperative-programming/ |access-date=2022-05-03 |website=IONOS Digitalguide |language=en}}</ref>
Line 31:
===Fortran===
[[FORTRAN]] (1958) was unveiled as "The IBM Mathematical FORmula TRANslating system." It was designed for scientific calculations, without [[String (computer science)|string]] handling facilities. Along with [[Declaration (computer programming)|declarations]], [[Expression (computer science)|expressions]], and [[Statement (computer science)|statements]], it supported:
* [[Array data structure|arrays]].
* [[subroutine]]s.
* [[For loop|"do" loops]].
 
It succeeded because:
* programming and debugging costs were below computer running costs.
* it was supported by IBM.
* applications at the time were scientific.<ref name="cpl_3rd-ch2-16">{{cite book
| last = Wilson
Line 49:
 
However, non IBM vendors also wrote Fortran compilers, but with a syntax that would likely fail IBM's compiler.<ref name="cpl_3rd-ch2-16"/> The [[American National Standards Institute]] (ANSI) developed the first Fortran standard in 1966. In 1978, Fortran 77 became the standard until 1991. Fortran 90 supports:
* [[Record (computer science)|records]].
* [[Pointer (computer programming)|pointers]] to arrays.
 
===COBOL===
Line 83:
| isbn = 0-201-71012-9
}}</ref> Emerging from a committee of European and American programming language experts, it used standard mathematical notation and had a readable structured design. Algol was first to define its [[Syntax (programming languages)|syntax]] using the [[Backus–Naur form]].<ref name="cpl_3rd-ch2-19"/> This led to [[Syntax-directed translation|syntax-directed]] compilers. It added features like:
* block structure, where variables were local to their block.
* arrays with variable bounds.
* [[For loop|"for" loops]].
* [[Subroutine#Functions|functions]].
* [[Recursion (computer science)|recursion]].<ref name="cpl_3rd-ch2-19"/>
 
Algol's direct descendants include [[Pascal (programming language)|Pascal]], [[Modula-2]], [[Ada (programming language)|Ada]], [[Delphi (software)|Delphi]] and [[Oberon (programming language)|Oberon]] on one branch. On another branch there's [[C (programming language)|C]], [[C++]] and [[Java (programming language)|Java]].<ref name="cpl_3rd-ch2-19"/>
Line 103:
 
Basic pioneered the [[Read–eval–print loop|interactive session]].<ref name="cpl_3rd-ch2-30"/> It offered [[operating system]] commands within its environment:
* The 'new' command created an empty slate.
* Statements evaluated immediately.
* Statements could be programmed by preceding them with a line number.
* The 'list' command displayed the program.
* The 'run' command executed the program.
 
However, the Basic syntax was too simple for large programs.<ref name="cpl_3rd-ch2-30"/> Recent dialects added structure and object-oriented extensions. [[Microsoft|Microsoft's]] [[Visual Basic]] is still widely used and produces a [[graphical user interface]].<ref name="cpl_3rd-ch2-31">{{cite book
Line 129:
| isbn = 0-201-71012-9
}}</ref> C is a relatively small language -- making it easy to write compilers. Its growth mirrored the hardware growth in the 1980s.<ref name="cpl_3rd-ch2-37"/> Its growth also was because it has the facilities of [[assembly language]], but uses a [[High-level programming language|high-level syntax]]. It added advanced features like:
* [[inline assembler]].
* arithmetic on pointers.
* pointers to functions.
* bit operations.
* freely combining complex [[Operators in C and C++|operators]].<ref name="cpl_3rd-ch2-37"/>
 
[[File:Computer-memory-map.png|thumb|right|Computer memory map]]