Mimir:Draft4 Chapter1

From Openitware
Jump to: navigation, search

Back to Table of Contents



Chapter 1: Introduction

"I know that I am mortal by nature, and ephemeral; but when I trace at my pleasure the windings to and fro of the heavenly bodies I no longer touch the earth with my feet: I stand in the presence of Zeus himself and take my fill of ambrosia."

What's in a Language?

Programming languages are the corner stone of all software. They provide software developers with the ability to tell a computer how to run and what tasks it needs to perform.

There is never an arbitrary decision on which programming language to use when beginning a software project. Each language available was created with a specific purpose in mind that the author felt they could not achieve through the use of other languages that were available. It is this fact along with the rapid evolution of computer hardware that have given us the vast amount of programming languages that are available today. Programming languages have and will continue to significantly evolve over the course of time just as their spoken language counterparts have.

What is a Paradigm?

It is interesting and useful to investigate the meaning of the word 'paradigm'

We will here look at the meaning of the word 'paradigm', as it appears in 'The American Heritage Dictionary of the English Language, Third Edition':


"An example that serves as pattern or model."


Another and slightly more complicated explanation stems from the 'The Merriam-Webster's Collegiate dictionary':


"A philosophical and theoretical framework of a scientific school or discipline within which theories, laws, and generalizations and the experiments performed in support of them are formulated"


Below we will first describe the meaning of the word 'paradigm' as we adopt it in this course. After that we describe related concepts, namely 'programming technique', 'programming style', and 'programming culture'.

  • Programming paradigm: A pattern that serves as a school of thoughts for programming of computers.
  • Programming technique: Related to an algorithmic idea for solving a particular class of problems
Examples: 'Divide and conquer' and 'program development by stepwise refinement'
  • Programming style:
    • The way we express ourselves in a computer program
    • Related to elegance or lack of elegance
  • Programming culture:
    • The totality of programming behavior, which often is tightly related to a family of programming languages
    • The sum of a main paradigm, programming styles, and certain programming techniques.

The main programming paradigms

in this Section we will identify four main programming paradigms and some of minor programming paradigms

  • Main programming paradigms:
    • The imperative paradigm
    • The functional paradigm
    • The logical paradigm
    • The object-oriented paradigm
  • Other possible programming paradigms:
    • The visual paradigm
    • One of the parallel paradigms
    • The constraint based paradigm

Overview of the Imperative Paradigm:

First Do This, Next Do That

The first do this, next do that is a short phrase which really in a nutshell describes the spirit of the imperative paradigm. The basic idea is the command, which has a measurable effect on the program state. The phrase also reflects that the order to the commands is important. 'First do that, then do this' would be different from 'first do this, then do that'.

In the itemized list below we describe the main properties of the imperative paradigm.

Characteristics:

  • Discipline and idea
    • Digital hardware technology and the ideas of Von Neumann
  • Incremental change of the program state as a function of time.
  • Execution of computational steps in an order governed by control structures
    • We call the steps for commands
  • Straightforward abstractions of the way a traditional Von Neumann computer works
  • Similar to descriptions of everyday routines, such as food recipes and car repair
  • Typical commands offered by imperative languages
    • Assignment, IO, procedure calls
  • Language representatives
    • Fortran, Algol, Pascal, Basic, C
  • The natural abstraction is the procedure
    • Abstracts one or more actions to a procedure, which can be called as a single command.
    • "Procedural programming"

We use several names for the computational steps in an imperative language. The word statement is often used with the special computer science meaning 'a elementary instruction in a source language'.

The word instruction is another possibility; We prefer to devote this word the computational steps performed at the machine level. We will use the word 'command' for the imperatives in a high level imperative programming language.

A procedure abstracts one or more actions to a procedure, which can be activated as a single action.

Overview of the Functional Paradigm

Evaluate an expression and use the resulting value for something

Functional programming is in many respects a simpler and more clean programming paradigm than the imperative one. The reason is that the paradigm originates from a purely mathematical discipline: the theory of functions. As described in Section 2.1, the imperative paradigm is rooted in the key technological ideas of the digital computer, which are more complicated, and less 'clean' than mathematical function theory.

Below we characterize the most important, overall properties of the functional programming paradigm. Needless to say, we will come back to most of them in the remaining chapters of this material.

Characteristics:

  • Discipline and idea
    • Mathematics and the theory of functions
  • The values produced are non-mutable
    • Impossible to change any constituent of a composite value
    • As a remedy, it is possible to make a revised copy of composite value
  • A Temporal
    • Time only plays a minor role compared to the imperative paradigm
  • Applicative
    • All computations are done by applying (calling) functions
  • The natural abstraction is the function
    • Abstracts a single expression to a function which can be evaluated as an expression
  • functions are first class values
    • Functions are full-fledged data just like numbers, lists, ...
  • Fits well with computations driven by needs
    • Opens a new world of possibilities

Overview of the logic paradigm

Answer a question via search for a solution

The logic paradigm is dramatically different from the other three main programming paradigms. The logic paradigm fits extremely well when applied in problem domains that deal with the extraction of knowledge from basic facts and relations. The logical paradigm seems less natural in the more general areas of computation.

Below we briefly characterize the main properties of the logic programming paradigm.

Characteristics:

  • Discipline and idea
    • Automatic proofs within artificial intelligence
  • Based on axioms, inference rules, and queries.
  • Program execution becomes a systematic search in a set of facts, making use of a set of inference rules

Overview of the object-oriented paradigm

Send messages between objects to simulate the temporal evolution of a set of real world phenomena

The object-oriented paradigm has gained great popularity in the recent decade. The primary and most direct reason is undoubtedly the strong support of encapsulation and the logical grouping of program aspects. These properties are very important when programs become larger and larger.

The underlying, and somewhat deeper reason to the success of the object-oriented paradigm is probably the conceptual anchoring of the paradigm. An object-oriented program is constructed with the outset in concepts, which are important in the problem domain of interest. In that way, all the necessary technicalities of programming come in second row.

As for the other main programming paradigms, we will now describe the most important properties of object-oriented programming, seen as a school of thought in the area of computer programming.

Characteristics:

  • Discipline and idea
    • The theory of concepts, and models of human interaction with real world phenomena
  • Data as well as operations are encapsulated in objects
  • Information hiding is used to protect internal properties of an object
  • Objects interact by means of message passing
    • A metaphor for applying an operation on an object
  • In most object-oriented languages objects are grouped in classes
    • Objects in classes are similar enough to allow programming of the classes, as opposed to programming of the individual objects
    • Classes represent concepts whereas objects represent phenomena
  • Classes are organized in inheritance hierarchies
    • Provides for class extension or specialization

This difference might be understood in terms of the following diagram:

Fig1.png


In procedural languages, code operates on data; in object-oriented languages, objects encapsulate code and data and interact with one another; in functional languages data flows through functions but has no separate existence of its own. That is, in procedural languages data is passive; in OO languages it is active; in pure functional languages it is ephemeral.

However, most functional languages (including LISP) provide a mechanism for keeping certain data in existence even when it is not flowing through functions. In LISP, this takes the form of what Common Lisp calls "special variables" - essentially equivalent to what in other programming languages are called "global variables". That is to say, though LISP is a functional language, it is not a pure functional language (though it could be used as one by avoiding imperative constructs.)