Mimir:Draft4 Chapter7

From Openitware
Revision as of 11:47, 15 February 2017 by Dfa1000 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Back to Table of Contents

Chapter 7: Procedural programming


The Procedural Paradigm


An introduction to the chapter should go here.


Procedural and declarative programming

Declarative programming is a programming paradigm, a style of building the structure and elements of computer programs, that expresses the logic of a computation without describing its control flow.Declarative programming often considers programs as theories of a formal logic, and computations as deductions in that logic space. Declarative programming may greatly simplify writing parallel programs. Subcategories of Declarative Programming include Logic Programming, Constraint Programming, and ConstraintLogicProgramming.The following operational characteristics might be used to judge the extent to which a programming model is declarative:

In Declarative Programming, order of statements and expressions should not affect program semantics. For example, they should not affect the termination characteristics and should not affect the observable IO properties, and ideally shouldn't affect performance.

In Declarative Programming, replication of a statement should not affect program semantics. What matters is that some fact or constraint exists, not how many times it is declared or computed. This allows refactoring and abstraction of statements, and is also a basis for many optimizations.

In procedural programing our code is organized into small "procedures" that use and change our data. In ColdFusion, we write our procedures as either custom tags or functions. These functions typically take some input, do something, then produce some output. Ideally your functions would behave as "black boxes" where input data goes in and output data comes out.

The key idea here is that our functions have no intrinsic relationship with the data they operate on. As long as you provide the correct number and type of arguments, the function will do its work and faithfully return its output.

Sometimes our functions need to access data that is not provided as a parameter, i.e., we need access data that is outside the function. Data accessed in this way is considered "global" or "shared" data.

The need for procedural programming

Procedural programming offers many benefits over simple sequential programming since procedural code:

  • is easier to read and more maintainable
  • is more flexible
  • facilitates the practice of good program design
  • allows modules to be reused in the form of code libraries.

Arithmetic operations, functions, subroutines, procedures


A function subprogram is invoked in an expression and returns a single value (a function result) that is used to evaluate the expression.The FUNCTION statement is the initial statement of a function subprogram. It takes the following form:

[prefix] FUNCTION name ([d-arg-list]) [RESULT (r-name)] prefix is one of the following:

type [keyword] keyword [type]

type is a data type specifier.

keyword could be Recursive, Pure, Elemental

name is the name of the function. If RESULT is specified, the function name must not appear in any specification statement in the scoping unit of the function subprogram.

d-arg-list is a list of one or more dummy arguments.

r-name is the name of the function result. This name must not be the same as the function name.


A subroutine subprogram is invoked in a CALL statement or by a defined assignment statement, and does not return a particular value.The SUBROUTINE statement is the initial statement of a subroutine subprogram. It takes the following form:

[prefix] SUBROUTINE name [([d-arg-list])]

prefix could be Recursive, Pure, Elemental

name is the name of the subroutine

d-arg-list is a list of one or more dummy arguments or alternate return specifiers (*).

Machine code to imperative programming

Computational steps, change of program state

Go-to dilemma

Procedures and Modularity: Structural and Modular programming

Language Representatives and Pragmatics (C, C++, Fortran, Pascal, Basic)

Design considerations: procedure, record, call

Program elements, native types and statements

Identifiers and literals

Operators and punctuators

Assignments, procedure calls


Iterations, conditional branching

Generic programming, parameterized functions, templates

Libraries, containers, I/O


A quick summary of the chapter should go here

Key Terms

A list of key terms should go here. This should be created using some sort of glossary type plugin.

Problem Sets

A list of practice problems

Top of Page - Prev Chapter - Next Chapter