Content deleted Content added
m Reverted edits by 59.153.103.24 (talk) to last revision by Citation bot: nonconstructive edits |
|||
(25 intermediate revisions by 21 users not shown) | |||
Line 1:
{{Short description|Type of programming paradigm in computer science}}
{{more citations needed|date=October 2011}}
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 |date=21 May 2021 |language=en |archive-date=2022-05-03 |archive-url=https://web.archive.org/web/20220503083342/https://www.ionos.com/digitalguide/websites/web-development/imperative-programming/ |url-status=live }}</ref>
==Procedural
[[Procedural programming]] is a type of imperative programming in which the program is built from one or more procedures (also termed [[subroutine]]s or functions). The terms are often used as synonyms, but the use of procedures has a dramatic effect on how imperative programs appear and how they are constructed. Heavy procedural programming, in which [[State (computer science)|state]] changes are localized to procedures or restricted to explicit arguments and returns from procedures, is a form of [[structured programming]]. Since the
Procedural programming could be considered a step toward declarative programming. A programmer can often tell, simply by looking at the names, arguments, and return types of procedures (and related comments), what a particular procedure is supposed to do, without necessarily looking at the details of how it achieves its result. At the same time, a complete program is still imperative since it ''fixes'' the statements to be executed and their order of execution to a large extent.
Line 15:
From this low-level perspective, the program state is defined by the contents of memory, and the statements are instructions in the native machine language of the computer. Higher-level imperative languages use [[variable (programming)|variable]]s and more complex statements, but still follow the same paradigm. [[Recipe]]s and process [[checklist]]s, while not [[computer program]]s, are also familiar concepts that are similar in style to imperative programming; each step is an instruction, and the physical world holds the state. Since the basic ideas of imperative programming are both conceptually familiar and directly embodied in the hardware, most computer languages are in the imperative style.
[[Destructive assignment|Assignment statements]], in imperative paradigm, perform an operation on information located in memory and store the results in memory for later use. High-level imperative languages, in addition, permit the [[Evaluation (disambiguation)#Computer_science|evaluation]] of complex [[Expression (programming)|expressions]], which may consist of a combination of [[Arithmetic#Arithmetic operations|arithmetic operations]] and [[function (mathematics)|function]] evaluations, and the assignment of the resulting value to memory. Looping statements (as in [[while loop]]s, [[do while loop]]s, and [[for loop]]s) allow a sequence of statements to be executed multiple times. Loops can either execute the statements they contain a predefined number of times, or they can execute them repeatedly until some condition is met. [[Conditional (programming)|Conditional]] [[Branch (computer science)|branching]] statements allow a sequence of statements to be executed only if some condition is met. Otherwise, the statements are skipped and the execution sequence continues from the statement following them. Unconditional branching statements allow an execution sequence to be transferred to another part of a program. These include the jump (called ''[[goto]]'' in many languages), [[switch statement|switch]], and the subprogram, [[subroutine]], or procedure call (which usually returns to the next statement after the call).
Early in the development of [[high-level programming language]]s, the introduction of the [[block (programming)|block]] enabled the construction of programs in which a group of statements and declarations could be treated as if they were one statement. This, alongside the introduction of [[subroutine]]s, enabled complex structures to be expressed by hierarchical decomposition into simpler procedural structures.
Line 52:
===COBOL===
[[COBOL]] (1959) stands for "COmmon Business Oriented Language." Fortran manipulated symbols. It was soon realized that symbols
| last = Wilson
| first = Leslie B.
Line 70:
}}</ref>
COBOL's development was tightly controlled, so dialects
===Algol===
Line 90:
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"/>
===
[[BASIC]] (1964) stands for "Beginner's All Purpose Symbolic Instruction Code." It was developed at [[Dartmouth College]] for all of their students to learn.<ref name="cpl_3rd-ch2-30">{{cite book
| last = Wilson
Line 99:
| page = 30
| isbn = 0-201-71012-9
}}</ref> If a student
Basic pioneered the [[Read–eval–print loop|interactive session]].<ref name="cpl_3rd-ch2-30"/> It offered [[operating system]] commands within its environment:
Line 139:
* The ''global and static data'' region is located just above the ''program'' region. (The program region is technically called the ''text'' region. It's where machine instructions are stored.)
:* The global and static data region is technically two regions.<ref name="geeksforgeeks">{{cite web
| date = 12 September 2011
| access-date = 25 May 2022
| archive-date = 6 November 2021
| archive-url = https://web.archive.org/web/20211106175644/https://www.geeksforgeeks.org/memory-layout-of-c-program/
| url-status = live
}}</ref> One region is called the ''initialized [[data segment]]'', where variables declared with default values are stored. The other region is called the ''[[.bss|block started by segment]]'', where variables declared without default values are stored.
:* Variables stored in the ''global and static data'' region have their [[Memory address|addresses]] set at compile-time. They retain their values throughout the life of the process.
Line 291 ⟶ 295:
// Used to allow multiple source files to include
// this header file without duplication errors.
// See: https://en.wikipedia.org/wiki/Include_guard
// ----------------------------------------------
#ifndef GRADE_H
Line 410 ⟶ 415:
public:
STUDENT ( const char *name );
~STUDENT();
GRADE *grade;
};
Line 430 ⟶ 436:
// Nothing else to do.
// -------------------
}
STUDENT::~STUDENT()
{
// deallocate grade's memory
// to avoid memory leaks.
// -------------------------------------------------
delete this->grade;
}
</syntaxhighlight>
Line 452 ⟶ 466:
<< student->grade->numeric
<< "\n";
// deallocate student's memory
// to avoid memory leaks.
// -------------------------------------------------
delete student;
return 0;
}
Line 481 ⟶ 501:
==See also==
* [[Functional programming]]
* [[Reactive programming]]
* [[History of programming languages]]
Line 498 ⟶ 517:
: ''Originally based on the article 'Imperative programming' by Stan Seibert, from [[Nupedia]], licensed under the [[GNU Free Documentation License]].''
{{Programming paradigms navbox}}
{{Types of programming languages}}
|