Phase Transition
Phase Transition
Phase Transition
(Top)
Procedural programming
Rationale and foundations of imperative programming
History of imperative and object-oriented languages
Examples
Toggle Examples subsection
Fortran
COBOL
Algol
Basic
C
C++
See also
Notes
References
Imperative
programming
46 languages
Article
Talk
Read
Edit
View history
Tools
From Wikipedia, the free encyclopedia
Procedural programming[edit]
The programming paradigm used to build programs for almost all computers
typically follows an imperative model.[note 1] Digital computer hardware is
designed to execute machine code, which is native to the computer and is usually
written in the imperative style, although low-level compilers and interpreters
using other paradigms exist for some architectures such as lisp machines.
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 variables and more complex
statements, but still follow the same paradigm. Recipes and process checklists,
while not computer programs, 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.
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 $TEST. COBOL (1960) and BASIC
(1964) were both attempts to make programming syntax look more like English. In
the 1970s, Pascal was developed by Niklaus Wirth, and C was created by Dennis
Ritchie while he was working at Bell Laboratories. Wirth went on to design
Modula-2 and Oberon. For the needs of the United States Department of Defense,
Jean Ichbiah and a team at Honeywell began designing 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 2012.
Examples[edit]
Fortran[edit]
● arrays
● subroutines
● "do" loops
It succeeded because:
However, non IBM vendors also wrote Fortran compilers, but with a syntax that
would likely fail IBM's compiler.[4] 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:
● records
● pointers to arrays
COBOL[edit]
COBOL (1959) stands for "COmmon Business Oriented Language." Fortran
manipulated symbols. It was soon realized that symbols did not need to be
numbers, so strings were introduced.[5] The US Department of Defense influenced
COBOL's development, with Grace Hopper being a major contributor. The
statements were English-like and verbose. The goal was to design a language so
managers could read the programs. However, the lack of structured statements
hindered this goal.[6]
Algol[edit]
Algol's direct descendants include Pascal, Modula-2, Ada, Delphi and Oberon on
one branch. On another branch there's C, C++ and Java.[7]
Basic[edit]
BASIC (1964) stands for "Beginner's All Purpose Symbolic Instruction Code." It
was developed at Dartmouth College for all of their students to learn.[8] If a
student did not go on to a more powerful language, the student would still
remember Basic.[8] A Basic interpreter was installed in the microcomputers
manufactured in the late 1970s. As the microcomputer industry grew, so did the
language.[8]
Basic pioneered the interactive session.[8] It offered operating system commands
within its environment:
However, the Basic syntax was too simple for large programs. [8] Recent dialects
added structure and object-oriented extensions. Microsoft's Visual Basic is still
widely used and produces a graphical user interface.[9]
C[edit]
C programming language (1973) got its name because the language BCPL was
replaced with B, and AT&T Bell Labs called the next version "C." Its purpose was
to write the UNIX operating system.[10] C is a relatively small language -- making it
easy to write compilers. Its growth mirrored the hardware growth in the 1980s. [10]
Its growth also was because it has the facilities of assembly language, but uses a
high-level syntax. It added advanced features like:
● inline assembler
● arithmetic on pointers
● pointers to functions
● bit operations
● freely combining complex operators[10]
Computer memory map
● 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. [11] One
region is called the initialized data segment, where variables
declared with default values are stored. The other region is called
the block started by segment, where variables declared without
default values are stored.
● Variables stored in the global and static data region have their
addresses set at compile-time. They retain their values throughout
the life of the process.
● The global and static region stores the global variables that are
declared on top of (outside) the main() function.[12] Global variables
are visible to main() and every other function in the source code.
On the other hand, variable declarations inside of main(), other functions, or
within { } block delimiters are local variables. Local variables also include
formal parameter variables. Parameter variables are enclosed within the
parenthesis of function definitions.[13] They provide an interface to the
function.
● Local variables declared using the static prefix are also stored in
the global and static data region.[11] Unlike global variables, static
variables are only visible within the function or block. Static
variables always retain their value. An example usage would be the
function int increment_counter(){ static int counter =
0; counter++; return counter;}
● The stack region is a contiguous block of memory located near the top
memory address.[14] Variables placed in the stack are populated from
top to bottom.[14] A stack pointer is a special-purpose register that
keeps track of the last memory address populated.[14] Variables are
placed into the stack via the assembly language PUSH instruction.
Therefore, the addresses of these variables are set during runtime. The
method for stack variables to lose their scope is via the POP
instruction.
● Local variables declared without the static prefix, including formal
parameter variables,[15] are called automatic variables[12] and are
stored in the stack.[11] They are visible inside the function or block
and lose their scope upon exiting the function or block.
● The heap region is located below the stack.[11] It is populated from the
bottom to the top. The operating system manages the heap using a
heap pointer and a list of allocated memory blocks.[16] Like the stack,
the addresses of heap variables are set during runtime. An out of
memory error occurs when the heap pointer and the stack pointer meet.
● C provides the malloc() library function to allocate heap memory.
[17]
Populating the heap with data is an additional copy function.
Variables stored in the heap are economically passed to functions
using pointers. Without pointers, the entire block of data would have
to be passed to the function via the stack.
C++[edit]
In the 1970s, software engineers needed language support to break large projects
down into modules.[18] One obvious feature was to decompose large projects
physically into separate files. A less obvious fearocess.
● The global and static region stores the global variables that are
declared on top of (outside) the main() function.[12] Global variables
are visible to main() and every other function in the source code.
● Local variables declared using the static prefix are also stored in
the global and static data region.[11] Unlike global variables, static
variables are only visible within the function or block. Static
variables always retain their value. An example usage would be the
function int increment_counter(){ static int counter =
0; counter++; return counter;}
● The stack region is a contiguous block of memory located near the top
memory address.[14] Variables placed in the stack are populated from
top to bottom.[14] A stack pointer is a special-purpose register that
keeps track of the last memory address populated.[14] Variables are
placed into the stack via the assembly language PUSH instruction.
Therefore, the addresses of these variables are set during runtime. The
method for stack variables to lose their scope is via the POP
instruction.
● Local variables declared without the static prefix, including formal
parameter variables,[15] are called automatic variables[12] and are
stored in the stack.[11] They are visible inside the function or block
and lose their scope upon exiting the function or block.
● The heap region is located below the stack.[11] It is populated from the
bottom to the top. The operating system manages the heap using a
heap pointer and a list of allocated memory blocks.[16] Like the stack,
the addresses of heap variables are set during runtime. An out of
memory error occurs when the heap pointer and the stack pointer meet.
● C provides the malloc() library function to allocate heap memory.
[17]
Populating the heap with data is an additional copy function.
Variables stored in the heap are economically passed to functions
using pointers. Without pointers, the entire block of data would have
to be passed to the function via the stack.
C++[edit]
In the 1970s, software engineers needed language support to break large projects
down into modules.[18] One obvious feature was to decompose large projects
physically into separate files. A less obvious feature was to decompose large
projects logically into abstract datatypes.[18] At the time, languages supported
concrete (scalar) datatypes like integer numbers, floating-point numbers, and
strings of characters. Concrete datatypes have their representation as part of
their name.[19] Abstract datatypes are structures of concrete datatypes — with a
new name assigned. For example, a list of integers could be called
integer_list.
● rocess.
● The global and static region stores the global variables that are
declared on top of (outside) the main() function.[12] Global variables
are visible to main() and every other function in the source code.
● Local variables declared using the static prefix are also stored in
the global and static data region.[11] Unlike global variables, static
variables are only visible within the function or block. Static
variables always retain their value. An example usage would be the
function int increment_counter(){ static int counter =
0; counter++; return counter;}
● The stack region is a contiguous block of memory located near the top
memory address.[14] Variables placed in the stack are populated from
top to bottom.[14] A stack pointer is a special-purpose register that
keeps track of the last memory address populated.[14] Variables are
placed into the stack via the assembly language PUSH instruction.
Therefore, the addresses of these variables are set during runtime. The
method for stack variables to lose their scope is via the POP
instruction.
● Local variables declared without the static prefix, including formal
parameter variables,[15] are called automatic variables[12] and are
stored in the stack.[11] They are visible inside the function or block
and lose their scope upon exiting the function or block.
● The heap region is located below the stack.[11] It is populated from the
bottom to the top. The operating system manages the heap using a
heap pointer and a list of allocated memory blocks.[16] Like the stack,
the addresses of heap variables are set during runtime. An out of
memory error occurs when the heap pointer and the stack pointer meet.
● C provides the malloc() library function to allocate heap memory.
[17]
Populating the heap with data is an additional copy function.
Variables stored in the heap are economically passed to functions
using pointers. Without pointers, the entire block of data would have
to be passed to the function via the stack.
C++[edit]
In the 1970s, software engineers needed language support to break large projects
down into modules.[18] One obvious feature was to decompose large projects
physically into separate files. A less obvious feature was to decompose large
projects logically into abstract datatypes.[18] At the time, languages supported
concrete (scalar) datatypes like integer numbers, floating-point numbers, and
strings of characters. Concrete datatypes have their representation as part of
their name.[19] Abstract datatypes are structures of concrete datatypes — with a
new name assigned. For example, a list of integers could be called
integer_list.
ture was to decompose large projects logically into abstract datatypes.[18] At the
time, languages supported concrete (scalar) datatypes like integer numbers,
floating-point numbers, and strings of characters. Concrete datatypes have their
representation as part of their name.[19] Abstract datatypes are structures of
concrete datatypes — with a new name assigned. For example, a list of integers
could be called integer_list.
C++ (1985) was originally called "C with Classes."[24] It was designed to expand
C's capabilities by adding the object-oriented facilities of the language Simula.[25]
● // grade.h
● // -------
●
● // 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
● #define GRADE_H
●
● class GRADE {
● public:
● // This is the constructor operation.
● // ----------------------------------
● GRADE ( const char letter );
●
● // This is a class variable.
● // -------------------------
● char letter;
●
● // This is a member operation.
● // ---------------------------
● int grade_numeric( const char letter );
●
● // This is a class variable.
● // -------------------------
● int numeric;
● };
● #endif
A constructor operation is a function with the same name as the class name. [26] It
is executed when the calling operation executes the new statement.
A module's other file is the source file. Here is a C++ source file for the GRADE
class in a simple school application:
● // grade.cpp
● // ---------
● #include "grade.h"
●
● GRADE::GRADE( const char letter )
● {
● // Reference the object using the keyword 'this'.
● // ----------------------------------------------
● this->letter = letter;
●
● // This is Temporal Cohesion
● // -------------------------
● this->numeric = grade_numeric( letter );
● }
●
● int GRADE::grade_numeric( const char letter )
● {
● if ( ( letter == 'A' || letter == 'a' ) )
● return 4;
● else
● if ( ( letter == 'B' || letter == 'b' ) )
● return 3;
● else
● if ( ( letter == 'C' || letter == 'c' ) )
● return 2;
● else
● if ( ( letter == 'D' || letter == 'd' ) )
● return 1;
● else
● if ( ( letter == 'F' || letter == 'f' ) )
● return 0;
● else
● return -1;
● }
Here is a C++ header file for the PERSON class in a simple school application:
● // person.h
● // --------
● #ifndef PERSON_H
● #define PERSON_H
●
● class PERSON {
● public:
● PERSON ( const char *name );
● const char *name;
● };
● #endif
Here is a C++ source file for the PERSON class in a simple school application:
● // person.cpp
● // ----------
● #include "person.h"
●
● PERSON::PERSON ( const char *name )
● {
● this->name = name;
● }
Here is a C++ header file for the STUDENT class in a simple school application:
● // student.h
● // ---------
● #ifndef STUDENT_H
● #define STUDENT_H
●
● #include "person.h"
● #include "grade.h"
●
● // A STUDENT is a subset of PERSON.
● // --------------------------------
● class STUDENT : public PERSON{
● public:
● STUDENT ( const char *name );
● ~STUDENT();
● GRADE *grade;
● };
● #endif
Here is a C++ source file for the STUDENT class in a simple school application:
● // student.cpp
● // -----------
● #include "student.h"
● #include "person.h"
●
● STUDENT::STUDENT ( const char *name ):
● // Execute the constructor of the PERSON superclass.
● // -------------------------------------------------
● PERSON( name )
● {
● // Nothing else to do.
● // -------------------
● }
●
● STUDENT::~STUDENT()
● {
● // deallocate grade's memory
● // to avoid memory leaks.
● // -------------------------------------------------
● delete this->grade;
● }
● // student_dvr.cpp
● // ---------------
● #include <iostream>
● #include "student.h"
●
● int main( void )
● {
● STUDENT *student = new STUDENT( "The Student" );
● student->grade = new GRADE( 'a' );
●
● std::cout
● // Notice student inherits PERSON's name
● << student->name
● << ": Numeric grade = "
● << student->grade->numeric
● << "\n";
●
● // deallocate student's memory
● // to avoid memory leaks.
● // -------------------------------------------------
● delete student;
●
● return 0;
● }
See also[edit]
● Functional programming
● Comparison of programming paradigms
● Reactive programming
● History of programming languages
● List of imperative programming languages
Notes[edit]
References[edit]
show
● V
● T
● E
show
● V
● T
● E
Category:
Programming paradigms
This page was last edited on 26 March 2024, at 21:17 (UTC).