Premium Essay

Examples Of Imperative Programming

Submitted By
Words 1429
Pages 6
# What is imperative programming?

Imperative programming is a [paradigm](https://mortoray.com/topics/paradigms/) that explicitly tells the computer what to do and how to do it. Unlike most other approaches it is a relatively concrete view on data and execution -- there isn't much mystery or abstract runtime behavior involved. The essential aspects of imperative programming are sequenced instructions and mutable data.

Imperative programming is the cornerstone of computing. CPUs primarily work as imperative execution engines, and compilers translate into this language. As the primary way of driving computers for most of our programming history, it's well represented in the language arena.

> I'm not saying all of computing works this way. A …show more content…
Imperative programming directly exposes the concept of memory. We get a canvas in which we can read and write values at will. This requires we understand values and pointers. Many languages go so far as allowing us to reinterpret memory as arbitrary types.

> Concurrent processing poses a problem to imperative programming. The general paradigm still holds, but the "as-if" rule is significantly loosened across threads. Only special instructions are guaranteed to have any ordering between parallel threads. Data is only required to be consistent if we go out of our way to make it consistent. Failing to pay tribute to the concurrent gods will invite evil spirits that wander the program and smash bits in infuriatingly hard-to-decipher patterns.

### Functions

Sequential ordering and mutable data define how functions work. A function may, like it's functional programming cousin, simply take input and provide a calculated result, but in imperative programming it's unlimited in what it can do. A function may have all sorts of side effects, changing global memory values, populating a database, loading a texture for the screen, starting a phone call, …show more content…
C programmers were structuring their code this way before C++ was even available. It's perhaps a refined of the paradigm but not fundamentally different. We're still giving the computer rather explicit instructions on how to structure data and the order in which things should be executed.

## Building blocks

Imperative components are linked to each via functions and variables. Programs are created by sequencing calls to many libraries and altering a global state, in memory, on disk, or over a network. We can loop on conditions, branch, or even call functions that wait for something to happen. Everything that happens is explicitly written, and ordered, in the code.

Though complete programs can be written strictly using this paradigm, it is no longer common except for the smallest of scripts. Imperative programming is well served when combined with other [paradigms](https://mortoray.com/topics/paradigms/) to create applications. A UI application will be connected with events, where the individual responders are written imperatively. Server deployment will be written with a declarative approach, but the individual rules use imperative code. A simulation package that has primarily functional calculations can be glued together with a bit of imperative

Similar Documents

Free Essay

Forex Analyst

...ANALYSIS OF PROGRAMMING LANGUAGE PARADIGMN BY GROUP 4 (M. Sc.) CSC 801 PROGRAMMING LANGUAGE PARADIGMNS TERM PAPER SUBMITTED TO THE DEPARTMENT OF COMPUTER SCIENCE, UNIVERSITY OF LAGOS, AKOKA June, 2015. ABSTRACT This is a survey on the programming languages paradigm: Imperative, Scripting, logic, Functional, object oriented and Markup. Our survey work involves a comparative study of these six programming languages with respect to the above programming paradigm using the following criteria: secure programming practices, web application development, OOP-based abstractions, reflection, Reusability, Portability, Reliability, Readability, Availability of compilers and tools, Familiarity, Expressiveness We study these languages in the context of the above mentioned criteria and the level of support they provide for each one of them. TABLE OF CONTENT 1. OVERVIEW OF PROGRAMMING LANGUAGE PARADIGMS 1.1 INTRODUCTION 1.2 CRITERIA OF LANGUAGE COMPARISON 2. IMPERATIVE LANGUAGES 2.1 Imperative Paradigm 2.1.2 Java as an Imperative Paradigm 2.1.3 Criteria 3. SCRIPTING LANGUAGES 3.1 Scripting Paradigm 3.2 Php as an Scripting Paradigm 3.3 Criteria 4. FUNCTIONAL LANGUAGES 4.1 Functional Paradigm 3.2 Php as an Scripting Paradigm 3.3 Criteria 5.1 LOGIC LANGUAGES 5.1.1 Readability 5.1.2 Ease of Learning 5.1.3 Ease of Maintenance 5.1.4 Extensibility 5.1.5 Pedagogy 5.1.6 Portability 6.1 OBJECT ORIENTED LANGUAGES (OOL) 6.1.1 Readability 6.1.2 Ease of Learning 6.1.3 Ease...

Words: 4013 - Pages: 17

Free Essay

A Computer Program

...enables a programmer to study and develop its algorithms. Computer source code is often written by computer programmers. Source code is written in a programming language that usually follows one of two main paradigms: imperative or declarative programming. Source code may be converted into an executable file (sometimes called an executable program or a binary) by a compiler and later executed by a central processing unit. Alternatively, computer programs may be executed with the aid of an interpreter, or may be embedded directly into hardware. Computer programs may be categorized along functional lines: system software and application software. Two or more computer programs may run simultaneously on one computer, a process known as multitasking. Computer programming is the iterative process of writing or editing source code. Editing source code involves testing, analyzing, and refining, and sometimes coordinating with other programmers on a jointly developed program. A person who practices this skill is referred to as a computer programmer, software developer or coder. The sometimes lengthy process of computer programming is usually referred to as software development. The term software engineering is becoming popular as the process is seen as an engineering discipline. Computer programs can be categorized by the programming language paradigm...

Words: 983 - Pages: 4

Premium Essay

Multiuse Platforms for Applications

...Programming languages are used to give instructions to a computer to complete a task (Burd 369). Object-oriented programming languages and imperative languages are similar in this way, but go about giving instructions differently. Object-oriented programming languages (OOS), use objects called procedures to manipulate data, in other words these methods are in a predetermined location and wait for a message arrive to execute a specific task (Burd 375). That task could be calculations, changing the color of text or displaying a video. One click on a particular object and the change to data or calculations are completed. Unlike imperative languages, object-oriented languages view data and programs as two parts which comes together to make an object (Burd 375). This makes it easier to maintain and promote reusability (Shelly et al. 250). I can also not fail to mention the object-oriented languages develop interactive user interfaces for real-time programming (Burd 375). This leads me to the integrated development environment (IDE) which consists of tools needed for faster development and testing (Burd 393). Imperative languages like Pascal have to be translated to binary CPU instructions before executing any tasks. They don’t have a graphical user interface like object-oriented programming (Burd 372). Imperative languages also use an interpreter to read source code which take up an enormous amount of resources in memory and CPU requirements while executing programs (Burd 388)...

Words: 659 - Pages: 3

Free Essay

Programing Paradigm

...Programming paradigm is a fundamental style of computer programming , a way of building the structure and elements of computer programs. There are six main programming paradigms: 1. imperative programming, imperative programming, which is based on procedural languages, literate programming ,which structures programs as a human-centered web, as in a hypertext essay –documentation is integral to the program, and the program is structured following the logic of prose exposition, rather than compiler convenience. 2. declarative programming, declarative programming paradigms were developed. In these languages the computer is told what the problem is, not how to solve the problem – the program is structured as a collection of properties to find in the expected result, not as a procedure to follow. Given a database or a set of rules, the computer tries to find a solution matching all the desired properties. The archetypical example of a declarative language is the fourth generation language SQL, as well as the family of functional languages and logic programming 3. functional programming , Functional programming is a subset of declarative programming. Programs written using this paradigm use functions, blocks of code intended to behave like mathematical functions. Functional languages discourage changes in the value of variables through assignment , making a great deal of use of recursion instead. 4. object-oriented programming , object-oriented languages...

Words: 393 - Pages: 2

Free Essay

Programming Lenguages

...ro1970’s Pascal is an influential imperative and procedural programming language, designed in 1968–1969 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring. A derivative known as Object Pascal designed for object-oriented programming was developed in 1985. ------------------------------- C is a general-purpose programming language initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. Like most imperative languages in the ALGOL tradition, C has facilities for structured programming and allows lexical variable scope and recursion, while a static type system prevents many unintended operations. Its design provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, most notably system software like the Unix computer operating system. ----------------------------------- Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics. Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is declarative: the program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations. The language was first conceived by a...

Words: 2012 - Pages: 9

Free Essay

Concepts of Programming Language Solutions

...Instructor’s Solutions Manual to Concepts of Programming Languages Tenth Edition R.W. Sebesta ©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. Preface Changes for the Tenth Edition T he goals, overall structure, and approach of this tenth edition of Concepts of Programming Languages remain the same as those of the nine earlier editions. The principal goals are to introduce the main constructs of contemporary programming languages and to provide the reader with the tools necessary for the critical evaluation of existing and future programming languages. A secondary goal is to prepare the reader for the study of compiler design, by providing an indepth discussion of programming language structures, presenting a formal method of describing syntax and introducing approaches to lexical and syntatic analysis. The tenth edition evolved from the ninth through several different kinds of changes. To maintain the currency of the material, some of the discussion of older programming languages has been removed. For example, the description of COBOL’s record operations was removed from Chapter 6 and that of Fortran’s Do statement was removed from Chapter 8. Likewise, the description of Ada’s generic subprograms was removed from Chapter 9 and the discussion of Ada’s asynchronous message passing was removed from Chapter 13. On the other hand, a section on closures, a section on calling subprograms indirectly, and a section on generic functions in...

Words: 7025 - Pages: 29

Premium Essay

Sequel

...This week the discussion moves to an extremely important part of relational database and that SQL, it stands for Structured Query Language and is a declarative programming language intended for the management of databases. Unlike other languages that use imperative programming, with declarative programming the end-user is establishing the code that is telling the computer what you would like to happen. Structured Query Language is a relatively simple language that a majority of all relational databases utilize in order to influence data in a database (“What is SQL?,” n.d.). This leads to the question as to why SQL is such a powerful language this is because SQL make available the ability to manipulate any portion of a database through the use of simple commands. Through the use SQL programming language a plethora of functions in a database such as creating and deleting tables, updating and changing data and retrieving specific data to name a few. By probably the single most powerful expression available to the database programmer in SQL is the employment of the “JOIN” command. At this point you may be thinking to yourself what makes this directive so powerful this is because the function allows the user to process a significant amount of data in a swift and efficient manner. While many individual databases may include two or four tables meanwhile businesses may have hundreds or even thousands of table with need to process data across these table this ultimately...

Words: 479 - Pages: 2

Free Essay

Inductive Triple Graphs

...Semantic Web. It can be considered as a knowledge representation common language based on a graph model. In the functional programming community, inductive graphs have been proposed as a purely functional representation of graphs, which makes reasoning and concurrent programming simpler. In this paper, we propose a simplified representation of inductive graphs, called Inductive Triple Graphs, which can be used to represent RDF in a purely functional way. We show how to encode blank nodes using existential variables, and we describe two implementations of our approach in Haskell and Scala. 1 Introduction RDF appears at the basis of the semantic web technologies stack as the common language for knowledge representation and exchange. It is based on a simple graph model where nodes are predominantly resources, identified by URIs, and edges are properties identified by URIs. Although this apparently simple model has some intricacies, such as the use of blank nodes, RDF has been employed in numerous domains and has been part of the successful linked open data movement. The main strengths of RDF are the use of global URIs to represent nodes and properties and the composable nature of RDF graphs, which makes it possible to automatically integrate RDF datasets generated by different agents. Most of the current implementations of RDF libraries are based on an imperative model, where a graph is represented as an adjacency list with pointers, or an incidence matrix. An algorithm...

Words: 5524 - Pages: 23

Free Essay

Database Concepts

...1. What are the advantages of a declarative language as opposed to a procedural language? ANSWER: The advantage of declarative programming languages is mainly two-fold. The programs are concise; this makes it easy even for non-programmers to obtain solutions. In the SQL example above, an analyst or business support person can get the desired information. Similarly, laypersons can write acceptable web pages with simple HTML and CSS commands. The second advantage of the declarative programming model is that repetitive imperative code that indicates how to solve things is provided in the computer system behind the scenes. Such code can be made highly efficient and can incorporate the best ideas from computing. It can take advantage of parallelism 2. What advantages might a procedural language have over a declarative language? ANSWER: Procedural programming is used for developing simple applications. The languages that use the procedural programming methodology include Pascal and C languages. Some of the benefits of the procedural programming methodology are: (1) Easy to read program code. (2) Easy maintainable program code as various procedures can be debugged in isolation. (3) Code is more flexible as you can change a specific procedure that gets implemented across the program. 3. Why do you think cross joins are allowed as a legitimate join? What uses can you see for joins? ANSWER: I think that a cross-join would be optimized in the client library, so that less...

Words: 317 - Pages: 2

Premium Essay

Programming Languages

...Unit 1 Research Assignment 1: Exploring Programming Languages Computers don't do anything without someone telling them what to do, much like the average teenager. To make the computer do something useful, you must give it instructions in either of the following two ways: * Write a program that tells a computer what to do, step by step, much as you write out a recipe. * Buy a program that someone else has already written that tells the computer what to do. Ultimately, to get a computer to do something useful, you (or somebody else) must write a program. A program does nothing more than tell the computer how to accept some type of input, manipulate that input, and spit it back out again in some form that humans find useful. Table 1 lists some common types of programs, the types of input that they accept, and the output that they produce. Essentially, a program tells the computer how to solve a specific problem. Because the world is full of problems, the number and variety of programs that people can write for computers is practically endless. But to tell a computer how to solve one big problem, you usually must tell the computer how to solve a bunch of little problems that make up the bigger problem. If you want to make your own video game, for example, you need to solve some of the following problems: * Determine how far to move a cartoon figure (such as a car, a spaceship, or a man) on-screen as the user moves a joystick. * Detect whether the cartoon figure...

Words: 3836 - Pages: 16

Free Essay

Pt2520 Unit 7 Research Assignment

...PT2520 Database Concept Unit 7 Research Assignment 1. What are the advantages of a declarative language as opposed to a procedural language? ANSWER: The advantage of declarative programming languages is mainly two-fold. The programs are concise; this makes it easy even for non-programmers to obtain solutions. In the SQL example above, an analyst or business support person can get the desired information. Similarly, laypersons can write acceptable web pages with simple HTML and CSS commands. The second advantage of the declarative programming model is that repetitive imperative code that indicates how to solve things is provided in the computer system behind the scenes. Such code can be made highly efficient and can incorporate the best ideas from computing. It can take advantage of parallelism 2. What advantages might a procedural language have over a declarative language? ANSWER: Procedural programming is used for developing simple applications. The languages that use the procedural programming methodology include Pascal and C languages. Some of the benefits of the procedural programming methodology are: (1) Easy to read program code. (2) Easy maintainable program code as various procedures can be debugged in isolation. (3) Code is more flexible as you can change a specific procedure that gets implemented across the program. 3. Why do you think cross joins are allowed as a legitimate join? What uses can you see for joins? ANSWER: I think that a cross-join would...

Words: 324 - Pages: 2

Free Essay

Student

...CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION This page intentionally left blank CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION R OB E RT W. S EB ES TA University of Colorado at Colorado Springs Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Vice President and Editorial Director, ECS: Marcia Horton Editor in Chief: Michael Hirsch Executive Editor: Matt Goldstein Editorial Assistant: Chelsea Kharakozova Vice President Marketing: Patrice Jones Marketing Manager: Yez Alayan Marketing Coordinator: Kathryn Ferranti Marketing Assistant: Emma Snider Vice President and Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Senior Production Project Manager: Marilyn Lloyd Manufacturing Manager: Nick Sklitsis Operations Specialist: Lisa McDowell Cover Designer: Anthony Gemmellaro Text Designer: Gillian Hall Cover Image: Mountain near Pisac, Peru; Photo by author Media Editor: Dan Sandin Full-Service Vendor: Laserwords Project Management: Gillian Hall Printer/Binder: Courier Westford Cover Printer: Lehigh-Phoenix Color This book was composed in InDesign. Basal font is Janson Text. Display font is ITC Franklin Gothic. Copyright © 2012, 2010, 2008, 2006, 2004 by Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Manufactured...

Words: 142312 - Pages: 570

Free Essay

Concepts of Programming Languages

...CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION This page intentionally left blank CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION R O B E RT W. S EB ES TA University of Colorado at Colorado Springs Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Vice President and Editorial Director, ECS: Marcia Horton Editor in Chief: Michael Hirsch Executive Editor: Matt Goldstein Editorial Assistant: Chelsea Kharakozova Vice President Marketing: Patrice Jones Marketing Manager: Yez Alayan Marketing Coordinator: Kathryn Ferranti Marketing Assistant: Emma Snider Vice President and Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Senior Production Project Manager: Marilyn Lloyd Manufacturing Manager: Nick Sklitsis Operations Specialist: Lisa McDowell Cover Designer: Anthony Gemmellaro Text Designer: Gillian Hall Cover Image: Mountain near Pisac, Peru; Photo by author Media Editor: Dan Sandin Full-Service Vendor: Laserwords Project Management: Gillian Hall Printer/Binder: Courier Westford Cover Printer: Lehigh-Phoenix Color This book was composed in InDesign. Basal font is Janson Text. Display font is ITC Franklin Gothic. Copyright © 2012, 2010, 2008, 2006, 2004 by Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Manufactured in the United States...

Words: 142253 - Pages: 570

Premium Essay

Cis-110 Technical Paper

...defining abstract data-types where implementation details are hidden and the unit has a clearly defined interface. OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones. OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces. Concepts of OOP: Objects which included classes, data abstraction and encapsulation, inheritance, polymorphism. Purely in terms of total instruction path length, a program coded in an imperative style, without using any subroutines at all, would have the lowest count. However, the binary size of such a program might be larger than the same program coded using subroutines (as in functional and procedural programming) and would reference more "non-local" physical instructions that may increase cache misses and increase instruction fetch overhead in modern processors. The paradigms that use subroutines extensively (including functional, procedural and object-oriented) and do not also use significant in-lining (via compiler optimizations) will, consequently, use a greater percentage of total resources on the subroutine linkages themselves. Object oriented programs that do not deliberately alter program state directly, instead using mutator methods (or "setters") to encapsulate these state changes, will, as a direct consequence, have a greater...

Words: 873 - Pages: 4

Premium Essay

The Language of Programming

...The language of Programming Computer programming is governed by many different languages, most of which are simple codes used to define the program. These languages can be specified by their practical application or simplicity of use. They all have the same basic function, which is to take high-level speech and convert it into low-level speech or machine code. Machine code is written in a cryptic series of 1s and 0s referred to as binary. Choosing which language to use is solely dependent on what kind of program you want to make. Writing in a programming language is as close as a computer will get to natural or spoken language. Some examples of the different languages are C++, COBOL, Python, COMPASS, Pascal, and Assembly language. While hard to understand at first, with a little practice the code comes naturally. C++ C++ is one of the most popular programming languages with application domains including systems software, application software, device drivers, embedded software, high-performance server and client applications, and entertainment software such as video games. Several groups provide both free and proprietary C++ compiler software, including the GNU Project, Microsoft, Intel and Embarcadero Technologies. C++ has greatly influenced many other popular programming languages, most notably C# and Java. C++ is sometimes called a hybrid language. It is possible to write object oriented or procedural code in the same program in C++. This has caused some concern that...

Words: 790 - Pages: 4