Computer Science
Imperative programming
Imperative programming is a programming paradigm that focuses on describing how a program operates by giving a sequence of commands to execute. It is based on the idea of changing the program state by executing a series of statements that modify variables and data structures. Imperative programming is widely used in software development and is the foundation of many programming languages.
Written by Perlego with AI-assistance
Related key terms
4 Key excerpts on "Imperative programming"
- eBook - ePub
- Timothy Colburn(Author)
- 2015(Publication Date)
- Routledge(Publisher)
We use one taken from a standard programming languages text: A programming language is a language that is intended to be used by a person to express a process by which a computer can solve a problem. 16 Any process, whether purely physical, computational, or otherwise, is a sequence of actions among objects. A computational process occurring on a computer is a curious entity because it is at once concrete and abstract. It is concrete because it can be described as the passing of electrons in circuits measured in microns, effecting changes in the state of semiconducting memory elements. On the other hand, the description of these state changes is a program that, as an expression in a formal language, is an abstraction of a process the programmer hopes is a correct model of the solution of a problem in the real world. What distinguishes the major programming paradigms is the kinds of object and action that the abstract process involves. The Imperative programming Paradigm The Imperative programming paradigm is so called because programs written in this paradigm “command” the computer to perform actions on objects, telling it how to behave. Assembly languages are imperative languages in which programs specify processes that involve objects like memory locations and registers, and actions like loading from and storing to memory, adding the contents of registers, shifting bits in registers, etc. Higher-order languages like C, Pascal, and Ada are imperative languages in which programs specify objects like procedures and matrices, and actions like calling a procedure or multiplying two matrices. The objects and actions in these languages are machine-independent, in that they do not directly specify things like memory addresses and register comparisons. But the objects and actions that are provided are only slightly removed from the machine level, and are fairly easily translated to machine level by the language’s compilers - eBook - ePub
- John Paul Mueller(Author)
- 2019(Publication Date)
- For Dummies(Publisher)
That's because no two people truly think completely alike. Each paradigm represents a different approach to the puzzle of conveying a solution to problems by using a particular methodology while making assumptions about things like developer expertise and execution environment. In fact, you can find entire sites that discuss the issue, such as the one at http://cs.lmu.edu/~ray/notes/paradigms/. Oddly enough, some languages (such as Python) mix and match compatible paradigms to create an entirely new way to perform tasks based on what has happened in the past. The following sections discuss just four of these other paradigms. These paradigms are neither better nor worse than any other paradigm, but they represent common schools of thought. Many languages in the world today use just these four paradigms, so your chances of encountering them are quite high. Imperative Imperative programming takes a step-by-step approach to performing a task. The developer provides commands that describe precisely how to perform the task from beginning to end. During the process of executing the commands, the code also modifies application state, which includes the application data. The code runs from beginning to end. An imperative application closely mimics the computer hardware, which executes machine code. Machine code is the lowest set of instructions that you can create and is mimicked in early languages, such as assembler. Procedural Procedural programming implements Imperative programming, but adds functionality such as code blocks and procedures for breaking up the code. The compiler or interpreter still ends up producing machine code that runs step by step, but the use of procedures makes it easier for a developer to follow the code and understand how it works. Many procedural languages provide a disassembly mode in which you can see the correspondence between the higher-level language and the underlying assembler - eBook - ePub
How Things Work
The Computer Science Edition
- Charles F. Bowman(Author)
- 2021(Publication Date)
- Chapman and Hall/CRC(Publisher)
Imperative vs. DeclarativeThe first way to classify high-level computer languages is by whether they are imperative or declarative.5 When using imperative languages, programmers specify the operations—i.e., the sequence of instructions—that, when executed, produce the desired result._______________5 As compared to natural languages, these terms differ slightly when used to describe computer languages.For example, consider the following C++ program that calculates a rectangle's area based on its length and width.6LISTING 11.1 EXAMPLE C++ PROGRAM #INCLUDE <IOSTREAM> USING NAMESPACE STD; INT MAIN( INT AC, CHAR* AV[] ) { INT AREA, LENGTH, WIDTH; WIDTH = 5; LENGTH = 10; AREA = LENGTH * WIDTH; COUT << "THE AREA IS: " << AREA << ENDL; }When it executes, the program will display the following output:LISTING 11.2 SAMPLE PROGRAM OUTPUT THE AREA IS: 50Don’t worry if you don’t understand every statement. (We’ll review other programming examples in more detail later in the text.) Just keep in mind that the programmer (me in this case) specified the length ( LENGTH = 10; ) and width ( WIDTH = 5; ) of the rectangle, then computed its area ( AREA = LENGTH * WIDTH; ).The last statement displays the result:COUT ‹‹ “THE AREA IS: ”‹‹ AREA ›› ENDL;In contrast, when using a declarative language, programmers specify the desired result, not the operations required to produce it. To demonstrate this approach, let's assume we had a database that contained a list of employees, as depicted in Table 11.1 - eBook - ePub
Anyone Can Code
The Art and Science of Logical Creativity
- Ali Arya(Author)
- 2020(Publication Date)
- Chapman and Hall/CRC(Publisher)
This allows us to use known methods of problem-solving and creativity within the context of programming. Also, it helps us use the algorithmic thinking approach in non-programming tasks and solve our other problems more efficiently. But let’s not get ahead of ourselves. We will talk about these in Chapter 2. But first, let’s talk about a few important subjects that will help you explore the book and understand why it is structured in this particular way. I.1 Software Development The word “software” refers to the collection of information that a computer uses. The “soft” part is due to the fact that it can easily change, as opposed to the physical device, or hardware, that is less flexible. 7 The terms “computer programing,” “coding,” “software development,” and “software engineering” are frequently used in the computer industry and literature. They are very much related but not quite the same. While there may be different definitions and interpretations, the most commonly used one defines computer programming as the act of creating a program, a set of executable instructions in a formal language that can be (after some steps) executed by a computer to achieve a particular purpose or result. 8 The key elements of this definition are (1) instructions or program, (2) language, (3) execution by a computer, and (4) purpose or results. Key Point: Programming is the process of creating a computer program (set of executable instructions) in a formal language for a particular purpose. The term Code is frequently used as equivalent to Program, but it can also mean a part of the program (as opposed to data) and also a specific representation of a program’s instruction (as in “machine code” vs. “human-readable code”). In this book, I make a distinction between code and data as two parts of a program: the information used by the program and the operations performed on that information
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.