INTRODUCTION

I Reasons for Studying Concepts of Programming Languages

The following are six reasons for studying concepts of programming languages:

1.  Increasing the capacity to express ideas:

Ø  In the process of developing software, programmers can only use the control structures, the data structures, and the abstractions provided by the language that they have chosen, and these constrains place limits in the forms of algorithms that they can construct. For example, the fact that C/C++ programming language provides no basic data type to represent and manipulate fixed decimal numbers makes it difficult to represent and process dollars and cents in a C/C++ program.

Ø  The awareness of a wider variety of programming language features can reduce such limitations in two different ways:

a)  By choosing the programming language with the best features to solve a particular problem.

b)  By simulating features from one language in those that do not have them. For example, the string and fixed decimal basic data types of PL/1 can be simulated in C/C++.

Ø  The study of programming language concepts builds an appreciation for valuable language features and encourages programmers to use them.

2.  Improving the background for choosing appropriate languages: that means to make an informed language choice for a new project.

3.  Increasing the ability to learn new languages: by having a thorough understanding of the fundamental concepts of programming languages, it becomes easier to see how these concepts are incorporated into the design of the language being learned.

4. Better understanding of the significance of implementation: the understanding of how the features of a programming language are implemented helps to write efficient codes and improves debugging skills: For example, knowing how function calls and recursions are implemented will help a programmer to write and use functions more intelligently. Also, knowing how certain data structures such as arrays, records/structures, or unions are implemented in a programming language may help in the debugging process of a program.

5. Better use of languages that are already known: Many contemporary programming languages are large and complex and programmers tend to be familiar only with the features of the language that they use. By studying the concepts of programming languages, a programmer can learn about previously unknown and unused features of a language that they already knew.

6.  Overall advancement of computing: the familiarity with programming language concepts by those in position to choose languages will help to make best languages widely accepted. For example FORTRAN was chosen over ALGOL 60 because programmers and software developer managers did not understand the conceptual design of ALGOL 60: they found its description difficult to read and understand, and did not appreciate the benefits of block structure, recursion, and well-structured controlled statements of ALGOL 60.

Exercise 1

1.  What are the six reasons for studying the concepts of programming languages?

2.  How can the awareness of a wider variety of programming language features reduces the limitations that the control structures, data structures and abstractions of a programming language impose on a programmer?

II Programming/Application Domains

The appropriate language to use often depends on the application domain for the problem to be solved: problems to be solved by digital computers may be classified according to the features that they require from programming languages. Examples of these features are basic and structured data types, operations on data, and control structures. In general, these features are provided in a programming language to allow programmers to efficiently write programs to solve problems in a particular application domain. These application domains and their associated languages follow:

1)  Scientific applications: are characterized by the following features:

a)  Simple data structures are needed: most common data structures are arrays and matrices.

b)  Problems require large numbers of floating-point arithmetic computations.

c)  Most common control structures are counting loops and selections

FORTRAN is the most commonly used language in this domain. An example of FORTRAN program is provided in pages 46 and 47.

2)  Business Applications: are characterized by the following features:

a)  Production of elaborate reports

b)  Need of precise ways for describing and storing character data (strings) and decimal numbers.

c)  Ability to specify decimal arithmetic operations

COBOL is the most commonly used language in this domain. An example of COBOL program is provided in pages 61, 62, and 63.

3)  Artificial Intelligence:

Ø  AI problems (game playing, theorem proving, knowledge representation and reasoning, natural language processing, . . . etc) require information to be represented in symbolic form rather than numeric form. Symbolic data is conveniently represented using linked lists (for names) and logical formulas (for facts and rules).

Ø  The most commonly used languages in this domain are LISP for list representation of data and PROLOG for logical formula representation of data. Examples of LISP structures and their internal representations are provided in pages 49 and 50, and an example of LISP function is provided in page 51. Examples of Prolog statements are provided in page 80.

4)  Systems Programming:

Ø  Systems software consists of the operating system and all the programming support tools of a computer system: compilers, assemblers, linkers, . . . etc.

Ø  These programs are mainly used for the operation of the computer system.

Ø  A language used to write software in this domain must provide low-level features that allow software interfaces to external devices to be written: system calls or APIs. They must also provide for fast execution.

Ø  C is the most commonly used system programming language.

5)  Web Software

Ø  A web site consists of one or more web pages.

Ø  A web page is a document or file that may contain text, graphics, music, animation, and video.

Ø  The content of a web document is specified by using a markup language such as HTML (XHTML).

Ø  Markup languages are not programming languages: they are used to specify the layout of information in Web documents. However, because of the need for dynamic Web contents, computations are often specified in a web documents.

Ø  Computations are specified in one of the following ways:

o  By embedding programming codes in an HTML (XHTML) document.

o  By making requests (in a Web document) that separate programs or procedures be executed either on the Web server or by the browser.

Ø  A Web application framework is a software framework that is designed to support the development of dynamic websites, Web applications, and Web services.

Ø  Many frameworks provide libraries for database access, frameworks to create templates, session management, and often promote code reuse.

Ø  The following are examples of Web application frameworks:

o  (Active Server Page) ASP.NET

o  Common Gateway Interface (CGI).

Ø  A Web programming languages either has an associated Web application framework or provides features that can be used for the development of Web application frameworks.

Ø  The following are examples of Web programming languages:

o  JavaScript Java Script statements are embedded in Web documents and are interpreted by the browser.

o  Java Two types of Java programs reside on a Web server:

§  Applets are executed by the browser on the client computer.

§  Servlets are executed on the Web server.

o  C# and VB.NET are the most popular languages used to create Web applications using the ASP.NET platform. However, since ASP.NET is built on the Common Language Runtime, any supported .NET language can be used. Programs/procedures written in these languages are either embedded in a Web document or located on the Web server and are executed on the Web server.

o  PHP is a server-side HTML/XHTML- embedded scripting language.

o  Perl is the ideal language for the CGI programming. CGI programs reside and are executed on the Web server.

Ø  Other Web programming languages are Python, Ruby, Lua, Common Lisp, and Smalltalk.

General Purpose Languages

Ø  A general purpose language is a language that can be used to develop applications in two or more domains. Examples of general purpose languages are Java, Ada, C#, Perl, and C++, PL/1, Pascal.


Special-Purpose Languages

RPG (Report Program Generator):

was introduced by IBM in the 1960s for the generation of reports.

It has a fixed coding structure with formats for:

a.  input specification (files and data)

b.  switch specification (Boolean)

c.  calculation and process

d.  output specification

Simulation Languages:

The simulation of discrete systems is done by modeling these systems with a series of state changes.

For example, in the simulation of a soda machine system, the state of the system can be the amount of coins received so far and the types of soda cans remaining with their quantities.

A simulation technique follows the system elements through their change of state and gathers quantitative or factual information.

This information is then used to predict the properties of the system under hypothetical situations.

GPSS (General -Purpose Simulation System)

- is a simulation language that provides the user with a set of different block types to represent the activities of the system being simulated.

- The line joining the blocks indicates the logical sequence in which the activities can be executed.

SIMULA

- is a language for system description and simulation with the concept of class

- A system in this case is viewed as a collection of independent entities (objects) interacting with each other.

- For example, for the soda machine system, the entities could be the soda machine, the can container, and the users.

- Systems are simulated by examining the life cycles of the entities of the system.


Exercise 2

1. You work in a company that wants to use only one programming language to implement all its programming applications. What is the most appropriate language in each of the following situations?

a.  All applications have a lot of floating-point arithmetic computations and require only arrays as the major data structure.

b.  All applications are used to compute payrolls and also to generate reports.

c.  Some applications have a lot of floating-point arithmetic computations and require only arrays as the major data structure, but others are used to compute payrolls and also to generate reports.

d.  All applications are used for game playing with symbolic manipulations of data represented as linked lists.

e.  All applications are used for the operation of the computer.

f.  All applications are embedded in HTML documents, and are interpreted on the server before the document is sent to a requesting browser.

g.  All applications are embedded in HTML documents and are interpreted by a browser that displays the document.

h.  All applications are common Gateway Interface (CGI) programs for the World Wide Web.

2.

a.  What are the major characteristics of each of the following programming domains: Scientific and business applications.

b.  What are the most commonly used languages in each of the above programming domains.

c.  Provide two special-purpose languages with their characteristics.

3.  Review questions 2, 3, 4, 5, and 6 page 32.

III Language Categories

Ø  High-level programming languages may be categorized as:

·  Imperative languages

·  Functional languages

·  Logic programming language

·  object-oriented programming languages.

Ø  Each of these categories of programming languages corresponds to the major software development methodologies.


Imperative Languages have the following major features:

a.  variables are used to represent memory locations

b.  assignment statements are used to store values in memory locations

c.  use of iteration as major form of repetition

d.  an algorithm is specified in great detail and the specific order of execution of the instructions/statements must be included.

e.  Examples of imperative languages are C, Pascal, PL/1, COBOL, FORTRAN

Ø  Visual Languages such as Visual Basic .Net form a subcategory of imperative languages.

Ø  These languages include capabilities for drag-and-drop generation of code segments.

Ø  They also provide a simple way to generate graphical user interfaces to programs.

Ø  For example, in VB.NET, the code to produce a display or a form control such as a button or a text box can be created with a single keystroke.

Ø  These capabilities are also available in all the other four .NET languages: C#, JScript (Microsoft’s version of JavaScript), J# (Microsoft version of Java) and managed C++.

Functional (Applicative) Languages are characterized by the following:

  1. computation is mostly done by applying functions to arguments
  2. Variables (symbols) do not necessarily represent memory locations and can be bound to values (atoms or lists) by special forms or when a function is called.
  3. recursion is the primary means of repetition

Ø  Examples of functional languages are Lisp, Scheme, ML (Meta Language), and Miranda

Ø  Examples of program constructs from Lisp:

(A B C D) is a simple list; A, B, C and D are atoms

(A (B C) D (E F)) is a nested list

(SETQ X 3) bind the value 3 to the symbol X

(+ 3 7) call to function + with arguments 3 and 7

Ø  Recursive definition of a function to compare two lists and return TRUE if both list are equal and FALSE otherwise.


(DEFUN EQUAL_LIST (LIST1 LIST2)

(COND

((ATOM LIST1) (EQ LIST1 LIST2))

((ATOM LIST2) NIL)

(T (AND (EQUAL_LIST (CAR LIST1) (CAR LIST2))

(EQUAL_LIST (CDR LIST1 (CDR LIST2))))))

(EQUAL_LIST (A B C) (A B C)) will return true whereas

(EQUAL_LIST (A B ) (A B C)) will return false.

Logic Programming Languages are characterized by the following:

  1. use of logical statements (facts and rules) to describe a program
  2. Programming in logic is nonprocedural because there is no way to specify in a program exactly how a result can be computed. The rules are specified in no particular order.
  3. computation is performed by deriving new facts from existing ones using an inference mechanism (resolution) and the rules

Ø  An example of logic program is Prolog

Ø  Examples of Prolog statements:

mother( ann, peter). ann is the mother of peter

father(bob, peter). bob is the father of peter

father(mark, ann).

father(roy, bob).

parent(x, y) :- father(x, y). x is a parent of y if it is his father

parent(x, y) :- mother(x, y). x is a parent of y if it is his mother