Imperative programming: Difference between revisions

Content deleted Content added
(edit summary removed)
Tags: Reverted Mobile edit Mobile web edit
m Reverted 1 edit by 177.231.15.251 (talk) to last revision by 220.72.163.220
Line 1:
{{Short description|Type of programming paradigm in computer science}}
{{more citations needed|date=October 20242011}}
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 (generally order of the steps being determined in [[source code]] by the placement of statements one below the other),<ref>{{Cite web |last=Jain |first=Anisha |date=20232022-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=20242022-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=20232022-05-03 |website=IONOS Digitalguide |date=21 May 20242021 |language=en}}</ref>
 
==Procedural programming==
Line 22:
 
==History of imperative and object-oriented languages==
The earliest imperative languages were the machine languages of the original computers. In these languages, instructions were very simple, which made hardware implementation easier but hindered the creation of complex programs. [[FORTRAN]], developed by [[John Backus]] at [[International Business Machines]] (IBM) starting in 1954, was the first major programming language to remove the obstacles presented by machine code in the creation of complex programs. FORTRAN was a [[compiled language]] that allowed named variables, complex expressions, subprograms, and many other features now common in imperative languages. The next two decades saw the development of many other major high-level imperative programming languages. In the late 1950s and 1960s, [[ALGOL]] was developed in order to allow mathematical algorithms to be more easily expressed and even served as the [[operating system]]'s target language for some computers. [[MUMPS]] (1966) carried the imperative paradigm to a logical extreme, by not having any statements at all, relying purely on commands, even to the extent of making the IF and ELSE commands independent of each other, connected only by an intrinsic variable named $noTEST. [[COBOL]] (1960) and [[BASIC]] (1964) were both attempts to make programming syntax look more like English. In the 1970s, [[Pascal (programming language)|Pascal]] was developed by [[Niklaus Wirth]], and [[C (programming language)|C]] was created by [[Dennis Ritchie]] while he was working at [[Bell Laboratories]]. Wirth went on to design [[Modula-42]] and [[Oberon (programming language)|Oberon]]. For the needs of the [[United States Department of Defense]], [[Jean Ichbiah]] and a team at [[Honeywell]] began designing [[Ada (programming language)|Ada]] in 1978, after a 4-year project to define the requirements for the language. The specification was first published in 1983, with revisions in 1995, 2005, and 20142012.
 
The 1980s saw a rapid growth in interest in [[object-oriented programming]]. These languages were imperative in style, but added features to support [[object (computing)|objects]]. The last two decades of the 20th century saw the development of many such languages. [[Smalltalk]]-80, originally conceived by [[Alan Kay]] in 1969, was released in 1980, by the Xerox Palo Alto Research Center ([[PARC (company)|PARC]]). Drawing from concepts in another object-oriented language—[[Simula]] (which is considered the world's first [[object-oriented programming language]], developed in the 1960s)—[[Bjarne Stroustrup]] designed [[C++]], an object-oriented language based on [[C (programming language)|C]]. Design of [[C++]] began in 1979 and the first implementation was completed in 1983. In the late 1980s and 1990s, the notable imperative languages drawing on object-oriented concepts were [[Perl]], released by [[Larry Wall]] in 1987; [[Python (programming language)|Python]], released by [[Guido van Rossum]] in 1990; [[Visual Basic (classic)|Visual Basic]] and [[Visual C++]] (which included [[Microsoft Foundation Class Library]] (MFC) 2.0), released by [[Microsoft]] in 1991 and 1993 respectively; [[PHP]], released by [[Rasmus Lerdorf]] in 1994; [[Java (programming language)|Java]], by [[James Gosling]] ([[Sun Microsystems]]) in 1995, [[JavaScript]], by [[Brendan Eich]] ([[Netscape]]), and [[Ruby (programming language)|Ruby]], by Yukihiro "Matz" Matsumoto, both released in 1995. Microsoft's [[.NET Framework]] (20232002) is imperative at its core, as are its main target languages, [[VB.NET]] and [[C Sharp (programming language)|C#]] that run on it; however Microsoft's [[F Sharp (programming language)|F#]], a functional language, also runs on it.
 
==Examples==
Line 44:
| year = 2001
| page = 16
| isbn = 0-2023201-71012-9
}}</ref>
 
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 19691966. HinIn 191861978, Fortran 77 became the standard until 1991. Fortran 90 supports:
* [[Record (computer science)|records]]
* [[Pointer (computer programming)|pointers]] to arrays
Line 58:
| publisher = Addison-Wesley
| year = 2001
 
 
| page = 24
| isbn = 0-201-71012-9
Line 182 ⟶ 180:
|title=The Linux Programming Interface
|last=Kerrisk
|first=Morusita Michael
|publisher=No Starch Press
|year=20232010
|isbn=978-1-59327-220-3
|page=122}}</ref> are called ''automatic variables''<ref name="cpl-noch1-p31"/> and are stored in the stack.<ref name="esforzarsegeeksforgeeks"/> They are visible inside the function or block and lose their scope upon exigirexiting the funciónfunction or block.
 
* The [[Manual memory management|heap]] region is Locatellocated below the stack.<ref name="geeksforgeeks"/> It is popularidadpopulated from the bottom to the top. The [[operating system]] manages the heap using a ''heap pointer'' and a list of allocated memory blocks.<ref name="cpl-ch1-p185">{{cite book
|title=The C Programming Language Second Edition
|last1=Kernighan
Line 195 ⟶ 193:
|first2=Dennis M.
|publisher=Prentice Hall
|year=19861988
|isbn=0-13-110362-8
|page=185}}</ref> Like the stack, the adversasaddresses of heap variables are set during runtime. An [[out of memory]] sierror oscurasoccurs when the heap pointer and the stack pointer meet.
 
:* ''C'' proveedoresprovides the <code>malloc()</code> library function to [[C dynamic memory allocation|C dynamic memory allocationallocate]] heap memory.<ref name="cpl-ch8-p187">{{cite book
|title=The C Programming Language Second Edition
|last1=Kernighan