(COM 113)
Programming Languages
Lesson 1
Introduction
Dr Joe Essien - (CSC 514) Organization of Programming Languages 2
OBJECTIVES
After this course, the reader
should be able to:
Have a vision of computer language evolution.
Distinguish between machine, assembly, and high-level
languages.
Understand the process of creating and running a program.
Distinguish between the different categories of languages:
procedural, object-oriented, functional, declarative, and special.
Become familiar with concepts of programming language
Dr Joe Essien - (CSC 514) Organization of Programming Languages 3
Why Study Programming
Languages?
In 1969, Sammet listed 120 programming
languages in common use – now there are more
than 2500 programming Languages
Most programmers never use more than a few.
◦ Some limit their career’s to just one or two.
The gain is in learning about their underlying
design concepts and how this affects their
implementation.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
4
The Six Primary Reasons
Increased ability to express ideas
Improved background for choosing appropriate
languages
Increased ability to learn new languages
Better understanding of significance of
implementation
Better use of languages that are already known
Overall advancement of computing
Dr Joe Essien - (CSC 514) Organization of Programming Languages
5
Reason #1 - Increased ability to
express ideas
The depth at which people can think is
heavily influenced by the expressive power
of their language.
It is difficult for people to conceptualize
structures that they cannot describe,
verbally or in writing.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
6
Expressing Ideas as Algorithms
This includes a programmer’s to develop
effective algorithms
Many languages provide features that can
waste computer time or lead
programmers to logic errors if used
improperly
◦ E. g., recursion in Pascal, C, etc.
◦ E. g., GoTos in FORTRAN, etc.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
7
Reason #2 - Improved background for
choosing appropriate languages
Many professional programmers have a
limited formal education in computer
science, limited to a small number of
programming languages.
They are more likely to use languages
with which they are most comfortable
than the most suitable one for a particular
job.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
8
Reason #3 - Increased ability to
learn new languages
Computer science is a relatively young
discipline and most software technologies
(design methodology, software development,
and programming languages) are not yet mature.
Therefore, they are still evolving.
A thorough understanding of programming
language design and implementation makes it
easier to learn new languages.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
9
Learning a New Language
It is easier to learn a new language if
you understand the underlying structures
of language.
Examples:
◦ It is easier for a BASIC program to learn Visual
Basic, FORTRAN than C.
◦ It is easier for a C++ programmer to learn Java.
◦ It is easier for a Scheme programmer to learn LISP.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
10
Evolution Map of Programming Languages
Dr Joe Essien - (CSC 514) Organization of Programming Languages
11
Dr Joe Essien - (CSC 514) Organization of Programming Languages
12
Reason #4 - Better understanding of
significance of implementation
Itis often necessary to learn about
language implementation; it can lead to a
better understanding of why the language
was designed the way that it was.
Fixing some bugs requires an
understanding of implementation issues.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
13
Reason #5 - Better use of languages
that are already known
To allow a better choice of programming
language
Some languages are better for some jobs
than others.
◦ Example – FORTRAN and APL for
calculations, COBOL and RPG for report
generation, LISP and PROLOG for AI, etc.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
14
Better Use of a Language
To improve your use of existing
programming language
By understanding how features are
implemented, you can make more
efficient use of them.
Examples:
Creating arrays, strings, lists, records.
Using recursions, object classes, etc.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
15
Reason #6 - Overall advancement
of computing
Frequently, the most popular language
may not be the best language available.
E.g., ALGOL 60 did NOT displace
Fortran.
◦ They had difficulty understanding its
description and they didn’t see the significance
of its block structure and well-structured
control statements until many years later.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
16
THE SOFTWARE CRISIS
The phrase software crisis alludes to a set of problems
encountered in the development of computer software during
the 1960s when attempting to build larger and larger software
systems using existing development techniques.
As a result:
◦ 1.Schedule and cost estimates were often grossly inaccurate.
◦ 2.Productivity of programmers could not keep up with
demand.
◦ 3.Poor quality software was produced.
Toaddress these problems the discipline of software
engineering came into being.
Dr Joe Essien - (CSC 514) Organization of Programming Languages 17
Programming Languages
Lesson 2
Principles of Programming
Languages
Dr Joe Essien - (CSC 514) Organization of Programming Languages 18
Computer Science as Programming
How to build systems.
◦ Better, faster, cheaper.
◦ Reliable, maintainable, extensible.
Evaluating and comparing systems.
◦ Performance, behavior, security.
◦ Compliance, usability.
What can and can’t be done.
◦ Algorithms and complexity.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
19
What is a Programming Language?
Definitions (1)
A programming language is a notational system for
describing computation in machine-readable and
human-readable form.
A programming language is an artificial language
that can be used to control the behavior of a
machine, particularly a computer
Programming languages, like human languages,
are defined through the use of syntactic and
semantic rules, to determine structure and meaning
respectively. 20
Dr Joe Essien - (CSC 514) Organization of Programming Languages
Definition (2)
Formal notation for specifying computations, independent of
a specific machine
Set of imperative commands used to direct computer to do
something useful
Programming languages are used to:
Facilitate communication about task
Organize Information
Manipulate Information
Express algorithms precisely
There are more than 2,500 documented programming languages
Dr Joe Essien - (CSC 514) Organization of Programming Languages
21
OPERATION OF A COMPUTER
PROGRAM
A computer program resides in primary memory where it is
represented as a set of machine instructions which in turn
are represented as sequences of binary digits.
At any point in time the computer is said to be in a
particular state.
A central feature of the state is the instruction pointer
which points to the next machine instruction to be
executed.
The execution sequence of a group of machine instructions
is known as the flow of control.
Dr Joe Essien - (CSC 514) Organization of Programming Languages 22
The Language of a Computer
Uses digital signals
◦ all 0's and 1's (binary)
◦ bits (BInary digiTs)
Data and commands stored in binary
◦ 8 bits in a byte
◦ ASCII character stored in a byte
◦ Integers stored in 2 or 4 bytes
Dr Joe Essien - (CSC 514) Organization of Programming Languages
23
Programming as Linguistic
Programming is an explanatory activity.
◦ To yourself, now and in the future.
◦ To whoever has to read your code.
◦ To the compiler, which has to make it run.
Explanations require language.
◦ To state clearly what is going on.
◦ To communicate ideas over space and time.
Therefore languages are of the essence in computer science.
◦ Programming languages, in the familiar sense.
◦ Description languages, design patterns, architecture languages,
specification languages.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
24
Declarative Programming
Resolution: Combining two or more statements
to produce a new statement (that is a logical
consequence of the originals).
◦ Example: (P OR Q) AND (R OR Q)
resolves to (P OR R)
◦ Resolvent: A new statement deduced by resolution
◦ Clause form: A statement whose elementary
components are connected by the Boolean operation
OR
Unification: Assigning a value to a variable so
that two statements become “compatible.”
Dr Joe Essien - (CSC 514) Organization of Programming Languages
25
DECLARATIVE v NON-
DECLARATIVE PROGRAMMING
Languages can also be classified by the
emphasis they put on “what is to be
achieved” against “how it is to be achieved”.
The first are said to be declarative (e.g.
functional and logic languages).
The second is said to be non-declarative or
procedural (e.g. imperative languages).
Dr Joe Essien - (CSC 514) Organization of Programming Languages 26
Non-computational
languages:
Non-computational languages, such as markup
languages like HTML are usually not considered
programming languages.
Oftena programming language is embedded in the
non-computational language.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
27
Programming Language Structure
Dr Joe Essien - (CSC 514) Organization of Programming Languages
28
Classification of programming
languages:
1. Machine, Assembler and High Level
Languages
2. Chronological order of development
3. Generations
4. Levels of abstraction (from machine level)
5. Declarative v Non-declarative
6. Paradigms
Dr Joe Essien - (CSC 514) Organization of Programming Languages 29
MACHINE LANGUAGE (1)
It is the lowest-level programming language.
Machine languages are the only languages
understood by computers.
While easily understood by computers, machine
languages are almost impossible for humans to use
because they consist entirely of numbers.
For example, a processor can execute the following
binary instruction expressed in machine language:
Binary: 10110000 01100001 (Hexadecimal: 0xb061)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
30
MACHINE LANGUAGE (2)
Thus,a program running on a computer is simply a
sequence of bits.
A program in this format is said to be in machine code.
We can write programs in machine code:
23fc 0000 0001 0000 0040
0cb9 0000 000a 0000 0040
6e0c
06b9 0000 0001 0000 0040
60e8
MACHINE LANGUAGE (3)
Earlycomputers programmed in
machine languages
◦ All binary numbers
Assembly language used mnemonic
codes
◦ Codes translated
into machine
language by a
program called
the "assembler"
Dr Joe Essien - (CSC 514) Organization of Programming Languages
32
ASSEMBLY LANGUAGE (1)
Assembly language (or assembler code) was our
first attempt at producing a mechanism for writing
programs that was more palatable to ourselves.
movl #0x1,n
• Of course a compare:
program written
in machine code, cmpl #oxa,n
in order to “run”, cgt
must first be end_of_loop
translated
(assembled) into acddl #0x1,n
machine code.
bra compare
end_of_loop:
ASSEMBLY LANGUAGE (2)
An assembly language is a low-level language for
programming computers.
The word "low" does not imply that the language is
inferior to high-level programming languages but rather
refers to the small or nonexistent amount of abstraction
between the language and machine language, because of
this, low-level languages are sometimes described as
being "close to the hardware."
Itimplements a symbolic representation of the numeric
machine codes and other constants needed to program a
particular CPU architecture.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
34
ASSEMBLY LANGUAGE (3)
A utility program called an assembler, is used to translate
assembly language statements into the target computer's machine
code.
The assembler performs a more or less isomorphic translation (a
one-to-one mapping) from mnemonic statements into machine
instructions and data.
Example to add 2 numbers in assembly language mnemonic
name "add"
mov al, 5 ; bin=00000101b
mov bl, 10 ; hex=0ah or bin=00001010b
add bl, al ; 5 + 10 = 15 (decimal) or hex=0fh or
bin=00001111b
The mnemonic "mov" and “add” are operation code or opcode, A
comma-separated list of arguments or parameters follows the
opcode;
Dr Joe Essien - (CSC 514) Organization of Programming Languages
35
Comparing Machine Language &
Assembly Language
Forexample, the machine code for adding two integers
might be:
010000110011101000111101010000010010101101000010
While the assembly language code might be:
LOAD A
ADD B
STORE C
◦ This causes the number in A to be added to the number
in B, and the result is stored for later use in C.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
36
High-level language (1)
High level languages read like
combination of English and algebra
write_string (outfile,cust_name,'l',23);
first_line = 1;
ord.read_order(infile);
while (!ord.done())
{
if ( !first_line) write_string (outfile," ",'l',23);
ord.print_order (outfile,part_list);
first_line = 0;
ord.read_order(infile);
}
◦ Translated into machine language by a
program called a compiler
Dr Joe Essien - (CSC 514) Organization of Programming Languages
37
High-level language (2)
High-level languages are relatively easy to learn
because the instructions bear a close resemblance to
everyday language, and because the programmer does
not require a detailed knowledge of the internal
workings of the computer.
Each instruction in a high-level language is equivalent
to several machine-code instructions, therefore it is
more compact than equivalent low-level programs.
High-level languages are used to solve problems and
are often described as problem-oriented languages
Dr Joe Essien - (CSC 514) Organization of Programming Languages
38
High-level language (3)
1. Source program created with an editor
2. Source code translated into machine
language by compiler
results in a .obj file (object code)
3. Linker combines common library
routines with object code
Results in a .exe file (executable code)
4. Loader brings executable code into
memory and it is run
Dr Joe Essien - (CSC 514) Organization of Programming Languages
39
High-level language (4)
Highlevel languages read like
combination of English and algebra
Translated into machine language by a program
called a compiler
Dr Joe Essien - (CSC 514) Organization of Programming Languages
40
High-level language (5)
Examples of HLL:
BASIC was designed to be easily learnt by first-time programmers;
COBOL is used to write programs solving business problems;
PASCAL is used for solving scientific and mathematical problems
FORTRAN is used for programs solving scientific and
mathematical problems.
With the increasing popularity of windows-based systems, the next
generation of programming languages was designed to facilitate
the development of GUI interfaces;
Examples: Visual Basic wraps the BASIC language in a graphical
programming environment.
Support for object-oriented programming has also become more
common, for example in C++ and Java.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
41
LANGUAGE LEVELS OF
ABSTRACTION
Level Instructions Memory handling
Low level Simple machine- Direct memory access
languages like instructions and allocation
High level Expressions and Memory access and
languages explicit flow of allocation through
control operators
Very high level Fully abstract Fully hidden memory
languages machine access and
automatic allocation
Programming Languages
Lesson 3
Programming Languages Paradigm
Dr Joe Essien - (CSC 514) Organization of Programming Languages 43
Scope of Programming Language Derivatives (1)
Software Domains Implementation/Execution Tools
Enterprise ArchiMate TOGAF ADM and ACF
Architecture ARIS Express Zachman Framework
Modelling Archi Development of Maturity Matrices
Ontology OWL Reasoners and Graphic
Development SPARQL Representation tools.
Cloud Computing Technologies
Software Behaviour Driven • SCRUM Methodologies
Development Object Oriented • Agile Development Methodologies
Methodologies Feature Driven Development • V-Model
Test Driven Development • Waterfall Development Method
Model Driven Development • Incremental Development Method
Business Process VPEC-T
Analysis IBM Requisite Pro
Software Modelling UML Visio 2010
ARIS STARUML
Software Visual Basic, C, C++, C#, Eclipse, Ruby
Development and VB.NET, Python , Perl Java, Java Scripts
Reporting Java Development Kit, IDE PHP, SCALA
Database Sybase ORACLE
Management TOAD
Dr Joe Essien - (CSC 514) Organization of Programming Languages
44
Scope of Programming Language Derivatives (2_
Software Domains Implementation/Execution Tools
Software Testing Selenium Test Complete
Atlassian JIRA GHERKINS Specifications
Documentation and Implementing solutions for Microsoft SharePoint
Archiving document collaboration and Disk imaging and mass deployment
management.
Web Based PHP HTML
Application JAVA XHTML
Operating platform Installation, configuration and Windows Servers and Operating
preparation management of servers, Systems
workstations, routers and SUSE Linux, HP-UX, IBM AIX
network infrastructure
Computer Systems Building computer systems Network resources, hubs, routers,
Engineering Technical support, Repairs, VPN
upgrades Printers, scanners, firewalls
Systems configuration and building
Network Windows, UNIX, SUSE Apple, Ubuntu, HP-UX, IBM AIX
Administration LINUX, Androids, etc
There are much more to this …
Dr Joe Essien - (CSC 514) Organization of Programming Languages
45
PROGRAMMING PARADIGMS
In science a paradigm describes a set of techniques that have
been found to be effective for a given problem domain.
In the context of programming languages we say that a
paradigm induces a particular way of thinking about the
programming task.
A paradigm can typically be expressed in terms of a single
principle (even if this is in fact an over simplification).
This principle must be supported by a set of techniques.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
46
Programming Language Paradigms
1. Imperative (e.g. Pascal, Ada, C).
2. Object-oriented (e.g. Java).
3. Functional (e.g. Haskell, SML).
4. Logic (e.g. Prolog).
Discussions
Principles of PLP
Concepts of PLP
Von Neumann Architecture
Dr Joe Essien - (CSC 514) Organization of Programming Languages 47
Programming Paradigms
A programming language is a problem-solving
tool.
program = algorithms +
Imperative style: data
good for decomposition
program = functions o
Functional style: functions
good for reasoning
Logic programming program = facts + rules
style: good for searching
program = objects +
Object-oriented
messages
style:
good for modeling(!)
Dr Joe Essien - (CSC 514) Organization of Programming Languages 1.48
Principles of PL Paradigm (1)
When programming systems with many processors, parallel or
process-oriented programming allows programmers to think
about applications as sets of concurrent processes using shared data
structures.
There are many possible models typically reflecting different ways
processors can be interconnected.
The most common are based on shared memory, distributed
memory with message passing, or a hybrid of the two.
Most parallel architectures use multiple von Neumann machines as
processing units.
Dr Joe Essien - (CSC 514) Organization of Programming Languages 49
Principles of PL Paradigm(2)
Specialized programming languages are designed for
parallel/concurrent computing.
Distributed computing rely on several sequential computers
interconnected to solve a common problem.
Such systems rely on interconnection middleware for
communication and information sharing.
Other processing paradigms were invented that went away from the von
Neumann model, an examples are Dataflow machines and LISP
Dr Joe Essien - (CSC 514) Organization of Programming Languages 50
Principles of PL Paradigm(3)
Low-level programming paradigm
Initially, computers were hard-wired or soft-wired and then
later programmed using binary code that represented control
sequences fed to the computer CPU.
This was difficult and error-prone. Programs written in binary
are said to be written in machine code, which is a very low-
level programming paradigm.
Hard-wired, soft-wired, and binary programming are considered
first generation languages.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
51
Principles of PL Paradigm(4)
Low-level programming paradigm
To make programming easier, assembly languages were developed.
These replaced machine code functions with mnemonics and
memory addresses with symbolic labels.
Assembly language programming is considered a low-level
paradigm although it is a 'second generation' paradigm.
Assembly languages support libraries and are quite sophisticated
conditional macro generation and pre-processing capabilities.
They also supported modular programming features such as
subroutines, external variables and common sections (globals),
enabling significant code re-use and isolation from hardware
specifics via use of logical operators.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
52
Principles of PL Paradigm(5)
Low-level programming paradigm
Assembly was, and still is, used for time-critical systems and
frequently in embedded systems.
Assembly programming can directly take advantage of a specific
computer architecture and, when written properly, leads to highly
optimized code.
However, it is bound to this architecture or processor and thus suffers
from lack of portability.
Assembly languages have limited abstraction capabilities, which
makes them unsuitable to develop large/complex software.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
53
Imperative PL Paradigm (1)
Often thought as a synonym for Procedural programming.
Specifying the steps the program must take to reach the desired state.
Based upon the concept of the procedure call.
Procedures, also known as routines, subroutines, methods, or functions
that contain a series of computational steps to be carried out.
Any given procedure might be called at any point during a program's
execution, including by other procedures or itself.
A procedural programming language provides a programmer a means to
define precisely each step in the performance of a task. The
programmer knows what is to be accomplished and provides through the
language step-by-step instructions on how the task is to be done.
Using a procedural language, the programmer specifies language
statements to perform a sequence of algorithmic steps.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
54
Imperative PL Paradigm(2)
Possible benefits:
Often a better choice than simple sequential or unstructured programming in many situations
which involve moderate complexity or require significant ease of maintainability.
The ability to re-use the same code at different places in the program without copying it.
An easier way to keep track of program flow than a collection of "GOTO" or "JUMP"
statements (which can turn a large, complicated program into spaghetti code).
The ability to be strongly modular or structured.
The main benefit of procedural programming over first- and second-
generation languages is that it allows for modularity, which is generally
desirable, especially in large, complex programs.
Modularity was one of the earliest abstraction features identified as
desirable for a programming language.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
55
Imperative PL Paradigm (3)
Scoping
Scoping is another abstraction technique that helps to keep procedures strongly
modular.
It prevents a procedure from accessing the variables of other procedures (and
vice-versa), including previous instances of itself such as in recursion.
Procedures
Procedures are convenient for making pieces of code written by different people
or groups represented in programming libraries.
specify a simple interface
self-contained information and algorithmics
reusable piece of code
Dr Joe Essien - (CSC 514) Organization of Programming Languages
56
Imperative PL Paradigm (4)
The focus of procedural programming is to break down a
programming task into a collection of variables, data structures, and
subroutines.
This is contrary to object-oriented programming which break s down
a programming task into objects with each "object" encapsulating its
own data and methods (subroutines).
The most important distinction is whereas procedural programming
uses procedures to operate on data structures, object-oriented
programming bundles the two together so an "object”.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
57
Imperative PL Paradigm (5)
The earliest imperative languages were the machine languages of the original computers. In
these languages, instructions were very simple, which made hardware implementation easier, but
hindered the creation of complex programs.
FORTRAN (1954) was the first major programming language to remove through abstraction
the obstacles presented by machine code in the creation of complex programs.
FORTRAN was a compiled language that allowed named variables, complex expressions,
subprograms, and many other features now common in imperative languages.
In the late 1950s and 1960s, ALGOL was developed in order to allow mathematical
algorithms to be more easily expressed.
In the 1970s, Pascal was developed by Niklaus Wirth, and C was created by Dennis Ritchie for
the needs of the United States Department of Defense, Jean Ichbiah and a team at Honeywell
began designing Ada in 1978.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
58
Object-Oriented PLD – Definition (1)
Object-oriented programming (OOP) is a programming paradigm that
uses "objects" – data structures encapsulating data fields and
procedures together with their interactions to design applications .
Identify components of the problem which are objects
Usually these are the nouns in the program description
Identify operations which are performed on the objects
Often these are the verbs in the program description
Associated programming techniques may include features such as
data abstraction, encapsulation, modularity and inheritance.
Many modern programming languages now support OOP.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
59
Object-Oriented PLD – Definition (1b)
Structured Programming
Thoroughly understand the problem
Determine;
the output desired
the required input
processing that will occur
Divide the problem into sub-problems
Other names for this process
structured design
top-down design
stepwise refinement
modular programming
Dr Joe Essien - (CSC 514) Organization of Programming Languages
60
Object-Oriented PLD – Class (2)
A class defines the abstract characteristics of a thing (object),
including that object’s characteristics (attributes, fields or
properties) and behaviors (the operations it can do, or methods,
operations or functionalities).
Classes provide modularity and structure in an object-oriented
computer program.
The code for a class is relatively self-contained (generally using
encapsulation).
Collectively, the properties and methods defined by a class are called
its members.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
61
Object-Oriented PLD – Object (3a)
An object is an individual of a class created at run-time through object
instantiation from a class.
The set of values of the attributes of a particular object forms its state.
The object consists of the state and the behavior that's defined in the
object's class.
The object is instantiated by implicitly calling its constructor, which is
one of its member functions responsible for the creation of instances of that
class.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
62
Components of an Object
Instance Variable: Variable within an
object
◦ Holds information within the object
Method: Procedure within an object
◦ Describes the actions that the object can
perform
Constructor: Special method used to
initialize a new object when it is first
constructed
Dr Joe Essien - (CSC 514) Organization of Programming Languages
63
Object-Oriented PLD – attribute (4)
An attribute, also called data member or member variable, is the data
encapsulated within a class or object.
In the case of a regular field (also called instance variable), for each instance
of the object there is an instance variable.
A static field (also called class variable) is one variable shared by all instances.
Attributes are an object’s variables that, upon being given values at
instantiation (using a constructor) represent the state of the object.
A class is a data structure that may contain different fields, defined to contain
the procedures that act upon it. It represents an abstract data type.
In pure object-oriented programming, the attributes of an object are local and
cannot be seen from the outside.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
64
Object-Oriented PLD – method (5i)
A method is a subroutine that is exclusively associated either with a class
(in which case it is called a class method or a static method) or with an
object (in which case it is an instance method).
A method usually consists of a sequence of programming statements to
perform an action, a set of input parameters to customize those actions, and
possibly an output value (called the return value).
Methods provide a mechanism for accessing and manipulating the
encapsulated state of an object.
Encapsulating methods inside of objects is what distinguishes object-
oriented programming from procedural programming.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
65
Object-Oriented PLD – method (5ii)
Instance methods are associated with an object
Class or Static methods are associated with a class.
The object-oriented programming paradigm intentionally favors the use of
methods for each and every means of access and change to underlying data:
Constructors: Creation and initialization of the state of an object. Constructors are called
automatically by the run-time system when an object declaration is encountered.
Retrieval and modification of state: accessor methods are used to access the value of a
particular attribute of an object.
Service-providing: A class exposes some “service-providing” methods to the exterior. A
class may also define private methods visible from the internal perspective of the object.
Destructor: When an object goes out of scope, or destroyed, its destructor is called by the
run-time system. This frees the memory and resources used during its execution.
Object-Oriented PLD – Inheritance (6)
Inheritance is a way to compartmentalize and reuse code by creating collections
of attributes and behaviors (classes) based on previously created classes.
The new classes, known as subclasses (or derived classes), inherit attributes and
behavior of the pre-existing classes, which are referred to as superclass.
The inheritance relationships of classes gives rise to a hierarchy.
Multiple inheritance can be defined whereas a class can inherit from more than
one superclass. A single class can then inherit from two classes that have members
bearing the same names, but yet have different meanings.
Abstract inheritance can be defined whereas abstract classes can declare member
functions that have no definitions and are expected to be defined in all of its
subclasses.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
67
Object-Oriented PLD – abstraction (7)
Abstraction is simplifying complex reality by modeling classes
appropriate to the problem, and working at the most appropriate level
of inheritance for a given aspect of the problem.
For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and
many more components. To build the Car class, one does not need to know how the
different components work internally, but only how to interface with them, i.e., send
messages to them, receive messages from them, and perhaps make the different objects
composing the class interact with each other.
Object-oriented programming provides abstraction through
composition and inheritance.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
68
Object-Oriented PLD – Encapsulation
and Information Hiding (8)
Encapsulation refers to the bundling of data members and member functions
inside of a common “box”, thus creating the notion that an object contains its
state as well as its functionalities
Information hiding refers to the notion of choosing to either expose or hide
some of the members of a class.
Encapsulation is achieved by specifying which classes may use the
members of an object.
The reason for encapsulation is to prevent clients of an interface from depending on those parts of the
implementation that are likely to change in the future, thereby allowing those changes to be made
more easily, that is, without changes to clients.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
69
Object-Oriented PLD – Polymorphism (9i)
Polymorphism
A method or operator can be abstractly applied in many different situations.
If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to
speak(), this may elicit an oink(). They both inherit speak() from Animal, but their derived class
methods override the methods of the parent class. This is overriding polymorphism.
Overloading polymorphism is the use of one method signature, or one
operator such as "+", to perform several different functions depending on
the implementation.
The "+" operator, for example, may be used to perform integer addition, float addition, list
concatenation, or string concatenation.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
70
Object-Oriented PLD – Polymorphism (9ii)
Many OOP languages also support parametric polymorphism, where
code is written without mention of any specific type and thus can be
used transparently with any number of new types.
C++ templates and Java Generics are examples of such parametric
polymorphism.
The use of pointers to a superclass type later instantiated to an object of
a subclass is a simple yet powerful form of polymorphism, such as used
in C++.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
71
Object-Oriented PLD – Examples (10)
Concerning the degree of object orientation the following distinction can
be made:
Languages that are "pure" OO languages treat everything in them consistently as an object,
from primitives such as characters and punctuation, all the way up to whole classes,
prototypes, blocks, modules, etc. They were designed specifically to facilitate, even
enforce, OO methods. Examples: Smalltalk, Eiffel, Ruby, JADE.
Languages designed mainly for OO programming, but with some procedural elements.
Examples: C++, C#, Java, Scala, Python.
Languages that are historically procedural languages, but have been extended with some
OO features. Examples: VB.NET (derived from VB), Fortran 2003, Perl, COBOL 2002,
PHP.
Languages with abstract data type support, but not all features of object-orientation,
sometimes called object-based languages. Examples: Modula-2, Pliant, CLU.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
72
Functional Programming Paradigm (1)
Functional programming is a programming paradigm that treats
computation as the evaluation of mathematical functions and
avoids state changes and mutable data.
It emphasizes the application of functions, in contrast to the
imperative programming style, which emphasizes changes in state.
Programs written using the functional programming paradigm are
more easily representable using mathematical concepts
Dr Joe Essien - (CSC 514) Organization of Programming Languages
73
Functional PLP – Declarative (2)
General programming paradigm in which programs express the logic of a
computation without describing its control flow. I otherwords, the programs
describe what the computation should accomplish, rather than how it should
accomplish it.
Contrary to imperative programming, where a program is a series of steps and
state changes describing how the computation is achieved. Declarative PLP
includes diverse languages/subparadigms such as:
Database query languages (e.g. SQL, Xquery)
Constraint programming
Logic programming
Functional programming
Dr Joe Essien - (CSC 514) Organization of Programming Languages
74
Reflective Programming (3i)
Reflection is the process by which a computer program can observe and
modify its own structure and behavior at runtime.
In most computer architectures, program instructions are stored as data -
hence the distinction between instruction and data is merely a matter of how
the information is treated by the programming language.
Normally, instructions are executed and data is processed; however, in some
languages, programs can also treat instructions as data and therefore make
reflective modifications.
Reflection is most commonly used in high-level virtual machine
programming languages like Smalltalk and scripting languages, and less
commonly used in manifestly typed and/or statically typed programming
languages such as Java, C, ML or Haskell.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
75
Reflective Programming (3ii)
Reflection-oriented programming includes self-examination, self-modification, and self-
replication.
Ultimately, reflection-oriented paradigm aims at dynamic program modification, which can be
determined and executed at runtime.
Some imperative approaches, such as procedural and object-oriented programming paradigms,
specify that there is an exact predetermined sequence of operations with which to process data.
The reflection-oriented programming paradigm, however, adds that program instructions can be
modified dynamically at runtime and invoked in their modified state.
That is, the program architecture itself can be decided at runtime based upon the data, services,
and specific operations that are applicable at runtime.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
76
Reflective Programming (3iii)
Reflection can be used for observing and/or modifying program execution at runtime. A
reflection-oriented program component can monitor the execution of an enclosure of
code and can modify itself according to a desired goal related to that enclosure.
Reflection can thus be used to adapt a given program to different situations
dynamically.
Reflection-oriented programming almost always requires additional knowledge,
framework, relational mapping, and object relevance in order to take advantage of
generic code execution mode.
It requires the translation process to retain in the executable code much of the higher-
level information present in the source code, thus leading to more bloated executables.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
77
Reflective Programming (3iv)
A language supporting reflection provides a number of features
available at runtime that would otherwise be very obscure or
impossible to accomplish in a lower-level language.
Some of these features are the abilities to:
Discover and modify source code constructions (such as code blocks,
classes, methods, protocols, etc.) as a first-class object at runtime.
Convert a string matching the symbolic name of a class or function
into a reference to or invocation of that class or function.
Evaluate a string as if it were a source code statement at runtime.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
78
Scripting Languages Paradigm (4i)
A scripting language is a language that allows control of another software
application.
"Scripts" are distinct from the core code of the application, as they are
usually written in a different language and are often created by the end-user.
Scripts are most often interpreted from source code, whereas application
software is typically first compiled to a native machine code or to an
intermediate code.
Early mainframe computers (in the 1950s) were non-interactive and instead
used batch processing. IBM's Job Control Language (JCL) is the archetype of
scripting language used to control batch processing.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
79
Scripting Languages Paradigm (4ii)
Types of Scripting Languages
Job control languages and shells
A major class of scripting languages has grown out of the automation of job
control, which relates to starting and controlling the behavior of system
programs.
Many of these languages' interpreters double as command-line interpreters
such as the Unix shell or the MS-DOS COMMAND.
Others, such as AppleScript offer the use of English-like commands to build
scripts. This combined with Mac OS X's Cocoa framework allows user to
build entire applications using AppleScript & Cocoa objects.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
80
Scripting Languages Paradigm (4iii)
Types of Scripting Languages – cont.
Application-specific scripting languages
Many large application programs include an idiomatic scripting language tailored
to the needs of the application user.
Likewise, many computer game systems use a custom scripting language to
express the game components’ programmed actions.
Languages of this sort are designed for a single application; and, while they may
superficially resemble a specific general-purpose language (e.g. QuakeC,
modeled after C), they have custom features that distinguish them.
An application-specific scripting language can be viewed as a domain-specific
programming language specialized to a single application.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
81
Functional Programming Paradigm (5)
Aspect-Oriented Programming Paradigm(i)
Aspect-oriented programming entails breaking down program logic into
distinct parts (so-called concerns or cohesive areas of functionality).
It aims to increase modularity by allowing the separation of cross-cutting
concerns, forming a basis for aspect-oriented software development.
AOP includes programming methods and tools that support the
modularization of concerns at the level of the source code
Aspect-oriented software development refers to a whole engineering
discipline.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
82
Logic Programming Paradigm (1)
Analysis-Coding-Execution
Algorithm :
A step-by-step problem-solving process in
which a solution is arrived at in a finite
amount of time
Steps must be simple, unambiguous
Steps must be performed in specified order
Steps must solve the problem
Dr Joe Essien - (CSC 514) Organization of Programming Languages
83
Logic Programming Paradigm (2)
Analysis-Coding-Execution cont …
Problem solving process
1. Analyze problem, design solution algorithm
2. Implement algorithm in a programming language, verify
3. Maintain program, adapting it to changes in problem
requirements
Dr Joe Essien - (CSC 514) Organization of Programming Languages
84
Logic Programming Paradigm (3)
Analysis-Coding-Execution (iii)
Analysis and
algorithm design
done apart from any
specific programming
Processing of the high-
language
level programming
language
Dr Joe Essien - (CSC 514) Organization of Programming Languages
85
Programming Languages
Lesson 4
Introducing Programming Languages
Dr Joe Essien - (CSC 514) Organization of Programming Languages 86
Objectives
To introduce several different concepts of
programming
To gain experience with these concepts by
using example programming languages
To understand concepts of syntax, translation,
abstraction, and implementation
Dr Joe Essien - (CSC 514) Organization of Programming Languages
87
Concepts of Programming
There are several ways to think about
computation:
a set of instructions to be executed
a set of expressions to be evaluated
a set of rules to be applied
a set of objects to be arranged
a set of messages to be sent and received
Dr Joe Essien - (CSC 514) Organization of Programming Languages
88
Some Programming archetypes
Procedural
examples: C, Pascal, Basic, Fortran
Functional
examples: Lisp, ML
Object-oriented
examples: C++, Java, Smalltalk
Rule-based (or Logic)
example: Prolog
Dr Joe Essien - (CSC 514) Organization of Programming Languages
89
Why so many Languages?
Most important: the choice of language depends on
how the human think about the problem.
Other considerations:
efficiency
compatibility with existing code
availability of translators
Some examples of Programming Languages
Software Development, e.g. VB.Net, Java, Eclipse, PHP
Document languages, e.g. LaTeX, Postscript
Command languages, e.g. bash, MATLAB
Markup languages, e.g. HTML and XML
Modeling languages, e.g. UML, ArchiMate,Aris
Dr Joe Essien - (CSC 514) Organization of Programming Languages
90
A Brief Chronology
Early 1950s “order codes” (primitive assemblers)
1957 FORTRAN the first high-level programming
language
1958 ALGOL the first modern, imperative language
1960 LISP, COBOL Interactive programming; business
programming
1962 APL, SIMULA the birth of OOP (SIMULA)
1964 BASIC, PL/I
1966 ISWIM first modern functional language (a
proposal)
1970 Prolog logic programming is born
1972 C the systems programming language
1975 Pascal, Scheme two teaching languages
1978 CSP Concurrency matures
1978 FP Backus’ proposal
1983 Smalltalk-80, Ada OOP is reinvented
1984 Standard ML FP becomes mainstream (?)
1986 C++, Eiffel OOP is reinvented (again)
1988 CLOS, Oberon,
Mathematica
1990 Haskell FP is reinvented
1990 Perl, Python, Ruby, Scripting languages become mainstream
s JavaScript
1995 Java Dr Joe Essien - (CSC 514) OOP is reinvented
Organization of Programmingfor the internet
Languages 91
How Programming Languages Differ (i)
Common Constructs:
basic data types (numbers, etc.); variables; expressions;
statements; keywords; control constructs; procedures;
comments; errors ...
Uncommon Constructs:
type declarations; special types (strings, arrays,
matrices, ...); sequential execution; concurrency
constructs; packages/modules; objects; general
functions; generics; modifiable state; ...
Dr Joe Essien - (CSC 514) Organization of Programming Languages
92
How Programming Languages Differ (ii)
Evolution of programming paradigms
Dr Joe Essien - (CSC 514) Organization of Programming Languages
93
How Programming Languages Differ (iii)
Language Levels Of Abstraction
Level Instructions Memory handling
Low level Simple machine-like Direct memory access
languages instructions and allocation
High level Expressions and Memory access and
languages explicit flow of allocation through
control operators
Very high Fully abstract Fully hidden memory
level machine access and
languages automatic allocation
Dr Joe Essien - (CSC 514) Organization of Programming Languages
94
How Programming Languages Differ (iv)
Difference in Boolean expressions
A relational operator between two arithmetic expressions
asks to determine if a relationship exists between the two
expressions
For example,
xValue < yValue
Dr Joe Essien - (CSC 514) Organization of Programming Languages
95
BASIC
Beginner's All purpose Symbolic Instruction Code
Easy to learn and use for non-science students and as a path
to Fortran and Algol
Must be ”pleasant and friendly"
Fast turnaround for homework
Free and private access
User time is more important than computer time
Well-suited for implementation on first PCs, e.g.,
Gates and Allen’s 4K Basic interpreter for the MITS
Altair personal computer (circa 1975)
Current popular dialects: Visual BASIC, VB.NET
Dr Joe Essien - (CSC 514) Organization of Programming Languages 96
FORTRAN (FORmula
TRANslator)
John Backus (1953) sought to write programs in conventional
mathematical notation, and generate code comparable to good
assembly programs.
John Backus’s team at IBM developed FORTRAN in 1955-1957.
No language design effort (made it up as they went along).
Most effort spent on code generation and optimization.
While FORTRAN was designed for numerical computation, it
included control structures, conditions and input/output.
FORTRAN’s popularity led to FORTRAN II in 1958, FORTRAN
IV in 1962, its standardization in 1966, revised standards coming
out in 1977 and 1990. The last standard is FORTRAN 2003
Dr Joe Essien - (CSC 514) Organization of Programming Languages
97
Fortran … (Hello World program)
Innovations
Symbolic notation for subroutines and functions
Assignments to variables of complex expressions
DO loops
PROGRAM HELLO
Comments DO 10, I=1,10
PRINT *,'Hello World'
Input/output formats
10 CONTINUE
Machine-independence STOP
Successes END
Easy to learn; high level
Promoted by IBM; addressed large user base
(scientific computing)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
98
Algol … (Hello World)
Environment of development:
1. Many other languages were being developed, all for
specific machines
2. No portable language; all were machine-dependent
3. No universal language for communicating algorithms
Goals of the language:
1. Must be translatable to machine code
2. Close to mathematical notation
BEGIN
3. Good for describing algorithms FILE F (KIND=REMOTE);
EBCDIC ARRAY E [0:11];
REPLACE E BY "HELLO WORLD!";
WHILE TRUE DO
BEGIN
WRITE (F, *, E);
END;
END.
Dr Joe Essien - (CSC 514) Organization of Programming Languages 99
APL
A Programming Language
Designed by K.Iverson at Harvard in late 1950’s
A language for programming mathematical
computations
especially those using matrices
Functional style and many whole array operations
Drawback is requirement of special keyboard
Dr Joe Essien - (CSC 514) Organization of Programming Languages
100
COBOL (COmmon Business Oriented Language)
History
Designed by committee of US computer manufacturers
Targeted business applications
Intended to be readable by managers (!)
Innovations
Separate descriptions of environment, data, and processes
Successes
Adopted as de facto standard by US DOD
Stable standard for 25 years
Still the most widely used PL for business applications (!)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
101
“Hello World” in COBOL
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. HELLOWORLD.
000300 DATE-WRITTEN. 02/05/96 21:04.
000400* AUTHOR BRIAN COLLINS
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. RM-COBOL.
000800 OBJECT-COMPUTER. RM-COBOL.
001000 DATA DIVISION.
001100 FILE SECTION.
100000 PROCEDURE DIVISION.
100200 MAIN-LOGIC SECTION.
100300 BEGIN.
100400 DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
100500 DISPLAY "HELLO, WORLD." LINE 15 POSITION 10.
100600 STOP RUN.
100700 MAIN-LOGIC-EXIT.
100800 EXIT.
Dr Joe Essien - (CSC 514) Organization of Programming Languages 102
LISP - LISt Processing language
AI research needed a language that:
Process data in lists (rather than arrays)
Handles symbolic computation (rather than numeric)
Syntax is based on the lambda calculus.
The program is a list and can extend itself at run time by constructing
another list (recursive)and executing it.
Pioneered functional programming
No need for variables or assignment.
Control via recursion and conditional expressions.
Suited to programming in functional and logic languages
Status
Still the dominant language for AI
COMMON LISP and Scheme are contemporary dialects
ML, Miranda, and Haskell are related languages
Dr Joe Essien - (CSC 514) Organization of Programming Languages
103
PL/I
• Computing situation in 1964 (IBM's point of view)
Scientific computing
• IBM 1620 and 7090 computers
• FORTRAN
• SHARE user group
Business computing
• IBM 1401, 7080 computers
• COBOL
• GUIDE user group
IBM’s goal:
• Develop a single computer (IBM 360) and a single programming
language (PL/I) that would be good for scientific and business
applications.
• Eventually grew to include virtually every idea in current practical
programming languages.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
104
PL/I
PL/I contributions:
1. First unit-level concurrency
2. First exception handling
3. Switch-selectable recursion
4. First pointer data type
5. First array cross sections
Comments:
• Many new features were poorly designed
• Too large and too complex
• Was (and still is) actually used for both scientific
and business applications
• Subsets (e.g. PL/C) developed which were more
manageable
Dr Joe Essien - (CSC 514) Organization of Programming Languages
105
“Hello World” in PL/1
HELLO: PROCEDURE OPTIONS (MAIN);
/* A PROGRAM TO OUTPUT HELLO WORLD
*/
FLAG = 0;
LOOP: DO WHILE (FLAG = 0);
PUT SKIP DATA('HELLO WORLD!');
END LOOP;
END HELLO;
Dr Joe Essien - (CSC 514) Organization of Programming Languages 106
Pascal (1971)
• Designed by Wirth, who quit the ALGOL 68
committee (didn't like the direction of that
work)
• Designed for teaching structured programming
• Small, simple
• Introduces some modest improvements, such as
the case statement
• Was widely used for teaching programming ~
1980-1995.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
107
C (1972-)
Designed for systems programming at Bell Labs
by Dennis Ritchie and colleagues.
Evolved primarily from B, but also ALGOL 68
Powerful set of operators, but poor type checking
Initially spread through UNIX and the availability
of high quality, free compilers, especially gcc.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
108
C++ (1985)
• Developed at Bell Labs by Stroustrup
• Evolved from C and SIMULA 67
• Facilities for object-oriented programming, taken
partially from SIMULA 67, added to C
• Also has exception handling
• A large and complex language, in part because it
supports both procedural and OO programming
• Rapidly grew in popularity, along with OOP
• ANSI standard approved in November, 1997
Dr Joe Essien - (CSC 514) Organization of Programming Languages 109
Program in C++ language
1 /* This program reads two integer numbers from the
2 keyboard and prints their product.
3 */
4 #include <iostream.h>
5
6 int main (void)
7 {
8 // Local Declarations
9 int number1;
10 int number2;
11 int result;
12 // Statements
13 cin >> number1;
14 cin >> number2;
15 result = number1 * number2;
16 cout << result;
17 return 0;
18 } // main
Dr Joe Essien - (CSC 514) Organization of Programming Languages 110
Smalltalk (1972-80)
• Developed at Xerox PARC by Alan Kay and colleagues
(esp. Adele Goldberg) inspired by Simula 67
• First compilation in 1972 was written on a bet to come up
with "the most powerful language in the world" in "a single
page of code".
• In 1980, Smalltalk 80, a uniformly object-oriented
programming environment became available as the first
commercial release of the Smalltalk language
• Pioneered the graphical user interface everyone now uses
• Industrial use continues to the present day
Dr Joe Essien - (CSC 514) Organization of Programming Languages
111
Functional Programming
Functional Programming is concerned with viewing a
program as a series of mathematical functions.
Introduced into programming the notions of:
◦ Initially designed as meta-language for theorem proving
◦ First class and higher order functions
◦ Polymorphism
◦ Lists
◦ Recursion
◦ Constructors
◦ Garbage Collection
Dr Joe Essien - (CSC 514) Organization of Programming Languages
112
Prolog … (Hello World)
History
Originatedat U. Marseilles (early 1970s), and compilers
developed at Marseilles and Edinburgh (mid to late 1970s)
Innovations
Theorem proving paradigm
Programs as sets of clauses: facts, rules and questions
Computation by “unification”
hello :- printstring("HELLO WORLD!!!!").
Based on formal logic
printstring([]).
Non-procedural printstring([H|T]) :- put(H), printstring(T).
Can be summarized as being an intelligent database system
that uses an inferrencing process to infer the truth of given
queries
Dr Joe Essien - (CSC 514) Organization of Programming Languages
113
Java
Developed at Sun in the early 1990s
with original goal of a language for
embedded computers
Principals:Bill Joy, James Gosling, Mike
Sheradin, Patrick Naughton
Original name, Oak, changed for copyright reasons
Based on C++ but significantly simplified
Supports only OOP
Has references, but not pointers
Includes support for applets and a form of concurrency (i.e.
threads)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
114
Object-Oriented Languages
History
Simula was developed by Nygaard and Dahl (early 1960s) in Oslo
as a language for simulation programming, by adding classes and
inheritance to ALGOL 60
Begin
while 1 = 1 do begin
outtext ("Hello World!");
outimage;
end;
End;
Smalltalk was developed by Xerox PARC (early 1970s) to drive
graphic workstations
Transcript show:'Hello World';cr
Dr Joe Essien - (CSC 514) Organization of Programming Languages
115
Object-Oriented Languages
In object-oriented languages, data structures and
algorithms support the abstraction of data and
endeavor to allow the programmer to use data in a
fashion that closely represents its real world use.
Data abstraction is implemented by use of
◦ Encapsulation – data and procedures belonging to
a class can only be accessed by that classes (with
noteworthy exceptions).
◦ Polymorphism – the same functions and operators
can mean different things depending on the
parameters or operands,
◦ Inheritance – New classes may be defined in
terms of other, simpler classes.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
116
Object-Oriented Languages
Innovations
Encapsulation of data and operations
(contrast ADTs)
Inheritance to share behaviour and interfaces
Successes
Smalltalk project pioneered OO user
interfaces
Large commercial impact since mid 1980s
Countless new languages: C++, Objective C,
Eiffel, Beta, Oberon, Self, Perl 5, Python,
Java, Ada 95 ...
Dr Joe Essien - (CSC 514) Organization of Programming Languages
117
Interactive Languages
Made possible by advent of time-sharing systems (early 1960s through mid
1970s).
BASIC
Developed at Dartmouth College in mid 1960s
Minimal; easy to learn
Incorporated basic O/S commands (NEW, LIST, DELETE, RUN, SAVE)
10 print "Hello World!"
20 goto 10
...
Dr Joe Essien - (CSC 514) Organization of Programming Languages
118
Interactive Languages ...
APL
Developed by Ken Iverson for concise description of numerical
algorithms
Large, non-standard alphabet (52 characters in addition to
alphanumerics)
Primitive objects are arrays (lists, tables or matrices)
Operator-driven (power comes from composing array operators)
No operator precedence (statements parsed right to left)
'HELLO WORLD'
Dr Joe Essien - (CSC 514) Organization of Programming Languages
119
Special-Purpose Languages
SNOBOL
First successful string manipulation language
Influenced design of text editors more than other PLs
String operations: pattern-matching and substitution
Arrays and associative arrays (tables)
Variable-length strings
OUTPUT = 'Hello World!'
END
...
Dr Joe Essien - (CSC 514) Organization of Programming Languages
120
Symbolic Languages ...
Lisp
Performs computations on symbolic expressions
Symbolic expressions are represented as lists
Small set of constructor/selector operations to create and
manipulate lists
Recursive rather than iterative control
No distinction between data and programs
First PL to implement storage management by garbage collection
Affinity with lambda calculus
(DEFUN HELLO-WORLD ()
(PRINT (LIST 'HELLO 'WORLD)))
Dr Joe Essien - (CSC 514) Organization of Programming Languages
121
4GLs
“Problem-oriented” languages
PLs for “non-programmers”
Very High Level (VHL) languages for specific problem domains
Classes of 4GLs (no clear boundaries)
Report Program Generator (RPG)
Application generators
Query languages
Decision-support languages
Successes
Highly popular, but generally ad hoc
Dr Joe Essien - (CSC 514) Organization of Programming Languages
122
“Hello World” in RPG
H
FSCREEN O F 80 80 CRT
C EXCPT
OSCREEN E 1
O 12 'HELLO WORLD!'
“Hello World” in SQL
CREATE TABLE HELLO (HELLO CHAR(12))
UPDATE HELLO
SET HELLO = 'HELLO WORLD!'
SELECT * FROM HELLO
Dr Joe Essien - (CSC 514) Organization of Programming Languages 123
Scripting Languages
History
Countless “shell languages” and “command languages” for operating
systems and configurable applications
> Unix shell (ca. 1971) developed as user echo "Hello, World!"
shell and scripting tool
> HyperTalk (1987) was developed at on OpenStack
show message box
Apple to script HyperCard stacks
put "Hello World!" into message box
end OpenStack
> TCL (1990) developed as embedding
language and scripting language for X
puts "Hello World "
windows applications (via Tk)
> Perl (~1990) became de facto web
scripting language print "Hello, World!\n";
Dr Joe Essien - (CSC 514) Organization of Programming Languages
124
Scripting Languages ...
Innovations
Pipes and filters (Unix shell)
Generalized embedding/command languages (TCL)
Successes
Unix Shell, awk, emacs, HyperTalk, AppleTalk, TCL, Python, Perl,
VisualBasic ...
Dr Joe Essien - (CSC 514) Organization of Programming Languages
125
Special languages
HTML (Hypertext Markup Language)
◦ An HTML file is stored on the server and can
be downloaded by a browser.
◦ The instructions are stored with the text.
◦ Any browser can read the instructions and
format the text according to the workstation
being used.
◦ HTML lets you use only ASCII characters for
both the main text and formatting instructions.
◦ Head, Body, and Tags
Dr Joe Essien - (CSC 514) Organization of Programming Languages
126
Common tags
Beginning Tag Ending Tag Meaning
---------------- ---------------- ----------------------------
<HTML> </HTML> document
<HEAD> </HEAD> document head
<BODY> </BODY> document body
<TITLE> </TITLE> document title
<Hi> </Hi> different header levels
<B> </B> boldface
<I> </I> Italic
<U> </U> underlined
<SUB> </SUB> subscript
<SUP> </SUP> superscript
<CENTER> </CENTER> centered
<BR> line break
<OL> </OL> ordered list
<UL> </UL> unordered list
<LI> </LI> an item in the list
<IMG> an image
<A> </A> an address (hyperlink)
Dr Joe Essien - (CSC 514) Organization of Programming Languages 127
The future?
Dynamic languages
◦ very active
Domain-specific languages
◦ very active
Visual languages
◦ many developments, but still immature
Modeling languages
◦ emerging from UML and MDE …
Dr Joe Essien - (CSC 514) Organization of Programming Languages
128
What you should know!
What is a programming language?
Discuss the reasons for studying Programming Languages
With the aid of a diagram, illustrate and discuss the
programming language structure
What are the concepts of Programming?
How do Programming Languages differ?
List four Programming Language Archetypes
List and Discuss the four Paradigms of PL
Distinguish between Declarative and Non- Declarative PL
What is Polymorphism, Inheritance and Encapsulation?
What are programming Language Levels of abstraction?
Dr Joe Essien - (CSC 514) Organization of Programming Languages
129
Programming Languages
Lesson 5
Statements and Constructs
Dr Joe Essien - (CSC 514) Organization of Programming Languages 130
How to write a program task
Decide what the task is about (objectives)
Decide steps needed to complete the task
Write the steps in pseudocode (written in
English) or as a flowchart (graphic symbols)
Translate into the programming language
Test the program and fix errors (debug)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
131
The composition of a typical imperative
program or program unit
Dr Joe Essien - (CSC 514) Organization of Programming Languages 132
What is pseudocode?
List of steps written in English
Like the instructions for a recipe
Must be in the right sequence
Imagine saying “bake the cake” and then “mix it up”
Sample of Pseudo code
Task: add two numbers Pseudocode:
Start
Get two numbers
Add them
Print the answer
End
Dr Joe Essien - (CSC 514) Organization of Programming Languages
133
What does a flowchart look like?
The pseudocode from the previous slide
would look like this as a flowchart:
Start
Print answer
Get 2 numbers
End
Add them
Dr Joe Essien - (CSC 514) Organization of Programming Languages
134
What are flowchart symbols?
Used at the beginning and
START/END end of each flowchart.
Shows when information/data
INPUT/OUTPUT comes into a program or is
printed out.
PROCESS Used to show calculations,
storing of data in variables,
and other “processes” that
take place within a program
DECISION Used to show that the
program must decide whether
is true or false. YES and NO
(or T/F) branches are shown.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
135
Another Sample: Calculating Age
Flowchart
Start
Pseudocode:
Get yr
◦ Start
◦ Get year born Calc age
◦ Calculate age
◦ Print age Print age
◦ If age > 50 print OLD
◦ End Y
OLD Age>50?
N
End
Dr Joe Essien - (CSC 514) Organization of Programming Languages
136
Command, Syntax and Data
Programming languages have rules about
semantics, mnemonics and expressions.
Data Types
Integer: Whole numbers
Real (float): Numbers with fractions
Character: Symbols
Boolean: True/false
Dr Joe Essien - (CSC 514) Organization of Programming Languages
137
Arrays
An array is a named
collection of homogeneous
items in which individual
items are accessed by their
place within the collection.
◦ The place within the
collection is called an index
Array variable of ten
Things accessed from 0..9
Dr Joe Essien - (CSC 514) Organization of Programming Languages
138
Elements of a Program (1)
Allprogramming languages have certain features in
common. For example:
◦ Variables
◦ Commands/Syntax (the way commands are structured)
◦ Loops
◦ Decisions
◦ Functions
Each programming language has a different set of rules
about these features.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
139
Elements of a Program (2)
Variables are part of almost every program.
A variable is a “place to put data” and is usually represented
by a letter or a word.
Variable names cannot contain spaces.
Some programming languages have very specific limits on
variable names.
Usually there are several ways to put information into a
variable. The most common way is to use the equal sign (=).
Dr Joe Essien - (CSC 514) Organization of Programming Languages
140
Elements of a Program (3)
Variable Declarations
Sometimes you must specify the type of data that will
be placed in a variable.
Here are some examples of data types:
◦ Numeric (numbers of all kinds)
◦ String (text, “strings of letters”)
◦ Integer (whole numbers)
◦ Long (large numbers)
◦ Boolean (true/false)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
141
Elements of a Program (4)
Variables
Variables may be classified as global or local.
A global variable is one that can be shared
by all parts of a program, including any
functions or sub-programs.
A local variable is one that is used only
within a certain part of the program, for
example, only in one function or sub-
program.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
142
Programming Language Constructs (1)
Encapsulation: A way of restricting access to the
internal components of an object or enforcing
information hiding.
Private
Public
Inheritance A construct that fosters reuse by allowing
an application to take an already-tested class and derive
a class from it that inherits its properties
Polymorphism The ability of a language to have
duplicate method names in an inheritance hierarchy and
to apply the method that is appropriate for the object to
which the method is applied.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
143
Programming Language Constructs (3)
Mapping of problem into solution
Inheritance and
polymorphism
combined allow the
programmer to build
useful hierarchies of
classes that can be
reused in different
applications
Dr Joe Essien - (CSC 514) Organization of Programming Languages
144
Loops
A loop
is a repetition of all or part of the
commands in a program.
A loop often has a counter (a variable)
and continues to repeat a specified
number of times.
A loop may also continue until a certain
condition is met (e.g., until the end of a
file or until a number reaches a set limit)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
145
Decisions
A program often needs to decide whether something is
true or false in order to see which way to continue.
Programs often use IF (or IF THEN or IF THEN ELSE)
statements to show a decision.
An IF statement always has a condition to check, often
a comparison between a variable and a number.
The IF statement also must specify what to do if the
condition/comparison is true.
These instructions (for “true”) may come after the
word THEN, or they may simply be listed.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
146
Selection Statement
For convenience, many high-level languages
include a case (or switch) statement
Allows us to make multiple-choice decisions
easier, provided the choices are discrete
Dr Joe Essien - (CSC 514) Organization of Programming Languages
147
Looping Statements
The while statement is used to repeat a course of action
Let’s look at two distinct types of repetitions
Count-controlled loops
◦ Repeat a specified number of times
◦ Use of a special variable called a loop control variable
The number of repetitions
is controlled by an event
that occurs within the body
Flow of control
of the loop itself of while
statement
Dr Joe Essien - (CSC 514) Organization of Programming Languages
148
Guarded Commands
Many PLs have the capability to generate an efficient
implementation of a n-way branch through guarded
commands.
The guarded command technique control program
execution by transfer of control or replacement of symbolic
names in GOTO statements by the actual target addresses.
if <expr 1> goto L1
if <expr 1> goto L2
Else goto L3
Dr Joe Essien - (CSC 514) Organization of Programming Languages
149
Guarded Commands - Example:
goto next
L(n-1): code for Stmt(n-1)
goto next
L(n): code for Stmt(n)
goto next
test: if (t=V1) goto L1
if (t=V2) goto L2
… if (t=V(n-1)) goto L(n-1) else goto L(n)
L1: if c goto L2
goto L3
L2: x= y+1
L3:
Dr Joe Essien - (CSC 514) Organization of Programming Languages
150
Subprogram Statements
We can give a section of code a name and
use that name as a statement in another
part of the program
When the name is encountered, the
processing in the other part of the
program halts while the named code is
executed
Dr Joe Essien - (CSC 514) Organization of Programming Languages
151
Subprogram Statements
Dr Joe Essien - (CSC 514) Organization of Programming Languages 152
Functions
There are times when the calling unit needs to give information
to the subroutine to use in its processing
These are small routines used to perform some of the tasks.
A parameter list is a list of the identifiers with which the
subroutine is to work, along with the types of each identifier
placed in parentheses beside the subroutine name
A function generally gets information from the main program,
performs some task, and returns information back to the
program.
Functions follow the same rules of syntax, etc. as the main
program.
JavaScript code is primarily made of a series of functions.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
153
Coding and Debugging
Coding means writing a program in an appropriate PL
Be sure the code is exact (spelling, capitals/lower case,
punctuation, etc).
Write part of the code, try it, then write more.
Debugging means running a program to fix mistakes.
Virtually no program works the first time you run it.
There are just too many places to make errors.
Syntax errors are very common causes of errors.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
154
Self-Check
1 A computer program is…
◦ A series of instructions to accomplish something
◦ A TV show
◦ Written in Egyptian hieroglyphics
◦ Can be written any way you want to
2 To “compile” a program means to…
◦ Translate it into English
◦ Translate it into binary code
◦ Pile up the punch cards used for the program
◦ Run the program as it was written
Dr Joe Essien - (CSC 514) Organization of Programming Languages
155
Self-Check
3 Pseudocode is…
◦ The program as it is written in a programming language
◦ The results of a program that makes secret codes
◦ The logic of a program written in English
◦ The logic of a program shown in a chart
4 A function in a program is…
◦ Something from trigonometry, like COSINE
◦ A sub-program, usually performing one task
◦ A way to check the accuracy of a program (a “function check”)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
156
Self-Check
5 A variable in a program is…
◦ A letter or word that represents a place to store data
◦ A decision made within a program
◦ A small sub-program used to find errors
6 Look at the flowchart section below. If the variable X is 5, what
will print (K or 1st)?
N Y
Print “K” X > 5? Print “1st”
K will be printed. The answer to the question “Is X greater than 5?” is NO, since X is equal to (not greater than) 5.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
157
Self-Check
7 Choose the correct flowchart symbol for each of these
statements.
AGE>65?
Calc. Tax
START
Print NAME
8 A function in a program is…
◦ Something from trigonometry, like COSINE
◦ A sub-program, usually performing one task
◦ A way to check the accuracy of a program (a “function check”)
Dr Joe Essien - (CSC 514) Organization of Programming Languages 158
Challenge 1
Try to write pseudocode and create a flowchart for a program that
calculates the average of three grades and prints the average.
The word GOOD should be printed only if the average is more than
80.
Possible pseudocode
◦ Start
◦ Get three grades
◦ Average them
◦ Print Average
◦ Average>80?
If Yes, print GOOD
◦ End
Dr Joe Essien - (CSC 514) Organization of Programming Languages
159
Challenge 1
START
Possible flowchart
Get 3 grades
◦ Start
◦ Get three grades
Calc avg
◦ Average them
◦ Print Average
◦ Average>80? Print avg
If Yes, print GOOD
◦ End Y
GOOD Avg>80?
END
Dr Joe Essien - (CSC 514) Organization of Programming Languages
160
Procedural Units
Local versus Global Variables
Formal versus Actual Parameters
Passing parameters by value versus reference
Procedures versus Functions
Dr Joe Essien - (CSC 514) Organization of Programming Languages
161
Programming Languages
Lesson 6
Application Domains of
Programming Languages
Dr Joe Essien - (CSC 514) Organization of Programming Languages 162
Programming Domains
Scientific Programming Languages
Business Programming Languages
Systems Programming Languages
Web Programming Languages
Dr Joe Essien - (CSC 514) Organization of Programming Languages
163
Programming domains (1)
Scientific Programming Languages
Mathematical computations
Games and Animation
Object and Symbol manipulation
Artificial Intelligence
Simulation
Business Programming Languages
Data processing and business procedures
Cobol, some PL/1, RPG, spreadsheets
Systems Programming Languages
Building operating systems and utilities
C, PL/S, ESPOL, Bliss, some Algol and derivitaves
Web Programming Languages
Building web based applications
HTML, PHP, Java
Dr Joe Essien - (CSC 514) Organization of Programming Languages
164
Scientific Programming Languages
These applications usually involve symbolic
computation, simulation, objects, symbols and
numbers.
The most common data structure is the list, not the
matrix or array as in scientific computing and not the
record as in business computing
Artificial intelligence requires more flexibility than
other programming domains as it deals with
emulating human-style reasoning on a computer.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
165
Business Programming Languages
Commercial data processing was one of the
earliest commercial applications of
computers.
The U.S. Defense Dept. sponsored the effort
to develop COBOL (Common Business-
Oriented Language), which was standardized
in 1960, revised in 1961 & 1962, re-
standarized in 1968, 1974, and 1984.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
166
Systems Programming Languages
Assembly languages were used for a
very long time operating systems
programming because of its power and
efficiency.
CPL, BCPL, C and C++ were later
developed for this purpose.
Other languages for systems
programming included PL/I, BLISS,
and extended ALGOL.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
167
Web Programming Languages
Diverse collection of languages:
Markup (e.g., HTML) – used for annotating a document in
a manner that can be distinguished from the text.
Scripting (e.g., PHP) - the language that enable the script
to run these commands and typically include control
structures such as if-then-else and while-do.
General-purpose (e.g., Java) – can be used for a wide
range of programming jobs.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
168
Language Evaluation Criteria
Readability – the ease with which programs
can be read and understood.
Writability – the ease with which programs
can be developed for a given program
domain.
Reliability – the extent to which a program
will perform according to its specifications.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
169
Language Evaluation Criteria -
Readability
Meaning of Machine Readability
A language is considered machine-readable if it can be
translated efficiently into a form that the computer can
execute.
This requires that:
A translation algorithm exists.
The algorithm is not too complex.
We can ensure machine readability by requiring that
programming languages be context-free languages.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
170
Language Evaluation Criteria -
Readability
Meaning of Human
Readability
Generally this requires a programming language to
provide enough abstractions to make the algorithms
clear to someone who is not familiar with the
program’s details.
As programs gets larger, making a language readable
requires that the amount of detail is reduced
This implies that changes in one part of a program
have a limited effect on other parts of the program.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
171
Language Evaluation Criteria -
Readability
What Contributes to Readability
There are five characteristics of programming
languages that contribute to readability:
Simplicity
Orthogonality
Control Statements
Data types and Structures
Syntax
Dr Joe Essien - (CSC 514) Organization of Programming Languages
172
Language Evaluation Criteria -
Readability
What Contributes to Readability
Programming languages with a large number of basic
components are harder to learn
Most programmers using these languages tend to learn
and use subsets of the whole language.
Complex languages have multiplicity (more than one
way to accomplish an operation).
All of the following add one to the variable count in C:
count = count + 1;
count += 1; Referred to as Overloaded
count++; Operators
++count;
Dr Joe Essien - (CSC 514) Organization of Programming Languages
173
Language Evaluation Criteria -
Readability
Overloading operators can reduce the clarity of the
program’s meaning
Most syntactic features in a programming language can
enhance readability:
Identifier forms – older languages (like FORTRAN)
restrict the length of identifiers, which become less
meaningful.
Special words – in addition to while, do and for, some
languages use special words to close structures such as
endif and endwhile.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
174
Language Evaluation Criteria - Writability
Writability must be considered within the context of the
language’s target problem domain.
E.g., COBOL handles report generating very well but
matrices poorly. The reverse is true for APL.
A large and diverse set of construct is easier to misuse than
a smaller set of constructs that are combined under a
consistent set of rules. (This is simple and orthogonal)
Should support data abstractions that a programmer is
likely to use in a given problem domain. ( e.g. binary trees)
Dr Joe Essien - (CSC 514) Organization of Programming Languages
175
Language Evaluation Criteria - Reliability
Reliability is the assurance that a program will not
behave in unexpected or disastrous ways during
execution.
This sometimes requires the use of rules that are
extremely difficult to check at translation or
execution time.
Reliability and efficiency of translation are
frequently diametrically opposed.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
176
Language Evaluation Criteria - Reliability
Contributing Factors To Reliability
Type Checking – a large factor in program
reliability. Compile-time type checking is more
desirable. C’s lack of parameter type checking leads
to many reliability problems.
Exception Handling – the ability to catch run-time
errors and make corrections can prevent reliability
problems.
Aliasing – having two or more ways of referencing
the same data object can cause unnecessary errors.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
177
Cost of Use of Programming Languages
Cost of program execution
A slower program is more expensive to run on a slower computer.
In an era of faster, cheaper computer, this is less of a concern.
Cost of program translation
Optimizing compilers are slower than some other compilers designed
for student programs, which will not run as many times..
Cost of program creation, testing and use
How quickly can you get the program executing correctly.
Cost of program maintenance
How expensive will it be to modify the program when changes are
needed in subsequent years?
Dr Joe Essien - (CSC 514) Organization of Programming Languages
178
Programming Language Design
New methods of program development have led to advances
in language design: These included;
Structured programming languages
Data abstraction in object-oriented languages
Compilation
Pure Interpretation
Hybrid Implementation Systems
The Compiler program that translates the high-level language program
into machine code
Other factors that have influence on programming language design are;
Computer Architecture
Programming Methodologies
Dr Joe Essien - (CSC 514) Organization of Programming Languages
179
Compilers and Interpreters
A compiler produces machine code as output
and then executes the machine code in a
separate step
An interpreter translates a statement and then
executes the statement immediately
Dr Joe Essien - (CSC 514) Organization of Programming Languages
180
Compiler Diagram
Parser
Dr Joe Essien - (CSC 514) Organization of Programming Languages
181
Interpreter Diagram
Parser
Dr Joe Essien - (CSC 514) Organization of Programming Languages
182
Type Checking
A type system is a collection of rules for assigning type
expressions to the various parts of a program. A type checker
implements a type system or Translation Scheme.
P --> D; E
D--> D;D
D--> id :T { addtype(id.entry,T.type);}
T--> char {T.type= char;}
T--> integer {T.type=integer;}
T-->*T_1 {T.type=pointer(T_1.type);}
T--> array[num] of T_1 { T.type
=array(1..num.val,T_1.type); }
E.g. The type of an array includes the index set of an array, so a function
with an array argument can only be applied to arrays with that index set.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
183
Static and Dynamic Checking of Types
A sound type system eliminates the need for
dynamic checking for type errors. A language is
strongly typed if its compiler can guarantee that the
programs it accepts will execute without type
errors.
The type of each identifier must be declared before
the identifier is used. The type checker is a
translation scheme that synthesizes the type of
each expression from the type of its sub-
expressions.
Dr Joe Essien - (CSC 514) Organization of Programming Languages
184
Programming Languages
Lesson 7
Mathematical Expressions
Dr Joe Essien - (CSC 514) Organization of Programming Languages 185
Programming Logic and Mathematical
Expressions
Algebra and Boolean Logic
Binary Arithmetic and Number Systems
Combinational Logic Circuits
Sequential Logic Circuits
Dr Joe Essien - Computer Architecture
186
Programming Logic Systems
Analog devices and systems process time-varying signals that can take
on any value across a continuous range.
Analog Signal
Digital systems use digital circuits that process digital signals which
can take on one of two values, we call:
0 and 1 (digits of the binary number system)
or LOW and HIGH High
or FALSE and TRUE Low
Digital Signal
Digital computers represent the most common digital systems.
187
Dr Joe Essien - Computer Architecture
Boolean Algebra
Boolean Algebra named after George Boole who used
it to study human logical reasoning – calculus of
proposition.
Elements : true or false ( 0, 1)
Primary Operations: a OR b; a AND b, NOT a
e.g. 0 OR 1 = 1 0 OR 0 = 0
1 AND 1 = 1 1 AND 0 = 0
NOT 0 = 1 NOT 1 = 0
188
Dr Joe Essien - Computer Architecture
Digital (logic) Elements: Gates
Digital devices or gates have one or more inputs and produce an output
that is a function of the current input value(s).
All inputs and outputs are binary and can only take the values 0 or 1
A gate is called a combinational circuit because the output only depends
on the current input combination.
Digital circuits are created by using a number of connected gates such as
the output of a gate is connected to the input of one or more gates in
such a way to achieve specific outputs for input values.
189
Dr Joe Essien - Computer Architecture
Boolean Algebra and Logic Gates
Set of Elements: {0,1}
Set of Operations: {., + , ¬ }
x y x.y x y x+y x ¬x
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1 NOT
AND OR
x x
x.y x+y x x'
y y
Signals: High = 5V = 1; Low = 0V = 0
190
Dr Joe Essien - Computer Architecture
Logic Gates
Symbol set 1 Symbol set 2
(ANSI/IEEE Standard 91-1984)
a a
AND a.b & a.b
b b
a a
OR a+b + a+b
b b
NOT a 1 a'
a a'
a a
(a.b)' & (a.b)'
NAND b b
a a
NOR (a+b)' 1 (a+b)'
b b
a a
EXCLUSIVE OR ab =1 ab
b b
Dr Joe Essien - Computer Architecture 191
Truth Tables
Provide a listing of every possible combination of values of
binary inputs to a digital circuit and the corresponding outputs.
INPUTS OUTPUTS
… …
… …
Truth table
Example (2 inputs, 2 outputs)
inputs outputs
x y x.y x+y inputs outputs
0 0 0 0 x x.y
Digital
0 1 0 1 y circuit x+y
1 0 0 1
1 1 1 1
192
Dr Joe Essien - Computer Architecture
Logic Gates: The AND Gate
A
A.B
B A B A.B
0 0 0
Vcc
12 11 10 9 8
0 1 0
14 13
1 0 0
1 1 1
Truth table
1 2 3 4 5 6 7
Ground
Top View of a TTL 74LS family 74LS08 Quad 2-input AND Gate IC Package
193
Dr Joe Essien - Computer Architecture
Logic Gates: The OR Gate
A A B A+B
A+B
B 0 0 0
0 1 1
1 0 1
1 1 1
Truth table
Top View of a TTL 74LS family 74LS08 Quad 2-input OR Gate IC Package
194
Dr Joe Essien - Computer Architecture
Logic Gates: The NAND Gate
A
(A.B)'
A
(A.B)'
B B
NAND gate is self-sufficient (can build any logic circuit with it).
Can be used to implement AND/OR/NOT.
Implementing an inverter using NAND gate: x x'
A B (A.B)'
0 0 1
0 1 1
1 0 1
1 1 0
Truth table
Top View of a TTL 74LS family 74LS00 Quad 2-input NAND Gate IC Package
195
Dr Joe Essien - Computer Architecture
Logic Gates: The NOR Gate
A
B
(A+B)' A
(A+B)'
B
NOR gate is also self-sufficient (can build any logic circuit with it).
Can be used to implement AND/OR/NOT.
A B (A+B)'
0 0 1
0 1 0
1 0 0
1 1 0
Truth table
Top View of a TTL 74LS family 74LS02 Quad 2-input NOR Gate IC Package
196
Dr Joe Essien - Computer Architecture
Logic Gates: The XOR Gate
A B AB
A
AB 0 0 0
B
0 1 1
Vcc 1 0 1
14 13 12 11 10 9 8
1 1 0
Truth table
1 2 3 4 5 6 7
Ground
Top View of a TTL 74LS family 74LS86 Quad 2-input XOR Gate IC Package
197
Dr Joe Essien - Computer Architecture
Drawing Logic Circuits
When a Boolean expression is provided, we can
easily draw the logic circuit.
Examples:
F1 = xyz'
(note the use of a 3-input AND gate)
x
y F1
z z'
Exam Type question
198
Dr Joe Essien - Computer Architecture
Analyzing Logic Circuits
When a logic circuit is provided, we can analyze the circuit to obtain
the logic expression.
Example: What is the Boolean expression of F4?
F4 = (A'B'+C)'
A'
B'
F4
C
A'B' A'B'+C (A'B'+C)'
Exam Type question
199
Dr Joe Essien - Computer Architecture
Programming Languages
Implementation
Lesson 8
Runtime Considerations
Dr Joe Essien - (CSC 514) Organization of Programming Languages 200
Major Issues
What is a run-time?
Major components of run-time
◦ Computational Support
◦ I/O interfacing
◦ Storage Management
◦ Tasking interfaces
◦ Exception Handling
◦ Other operating system issues
The Run-Time
Simple operations generate direct machine
language (e.g. addition)
But modern languages have many high level
constructs
PLs generate calls to hidden routines called
the run-time.
Run-time is included silently in linked
program (standard libraries used)
The Compiler Run-Time
Part of the implementation
Not available directly to program
Interface may not be documented
Special calling sequences can be used
Special operating system interface
Delivered as part of the compiler
Computational Support
Some simple operations may not be
supported by instruction set
64-bit integer arithmetic
Conversion of fpt to integer
Overflow checking
Floating-point (emulation needed)
Long shifts
Square root
Handling Computational Support
Need very small high efficiency
routines, might possibly be in linable
Special calling sequences may be useful
(e.g. args in registers)
Assembly language may be reasonable
in this case
Implementation is target dependent
Language Considerations
Some languages have no high level
constructs, so need minimal run time
◦ For example, C, everything is done with
explicit procedure calls.
But other languages, e.g.
◦ C++ (stream operations)
◦ Ada (tasking)
◦ Java (automatic storage mgmt)
The Run-Time in C
Very small
◦ Usually only some computational routines.
Standard has many standard functions as part
of language
◦ These are explicit library routines
◦ Often part of the underlying OS
Command line interface needed
The Run-Time in Ada
Much more extensive
Tasking
Timing
Storage Management
Conversions (e.g. string to fpt)
Requires extensive library
Only partly target dependent
Other Languages
C++ nearer to C, but has
◦ Streams
◦ Exception Handling
Java, more extensive, adds
◦ Storage mgmt (garbage collection)
◦ Standardized arithmetic (IEEE )
◦ Interface to JBC/JVM
Other Languages (cont)
COBOL, much more extensive
Detailed complex I/O model
Includes full indexed files
SORT subsystem
INSPECT REPLACING
PICTURE editing
Display and packed numeric formats
Other Languages (cont)
Very high level languages
Setl, Python, GUILE, Visual Basic
Set operations
GUI operations
High level operating systems interfaces
E.g. COM/DCOM interfacing
Web interfacing
I/O interface
Language may have explicit I/O
statements, or rely on proc interface
In either case, have to map the language
notion of I/O to op sys
End of line (record vs stream)
Notion of file system (directories?)
Exception handling
Character sets (esp wide chars)
Implementing the I/O Interface
Two parts
Target independent code
Target dependent code
Target Independent code
Simply implements the language semantics
Using some abstractions
Target Dependent I/O
On top of operating system
Map language semantics to OS
semantics, deal with differences as well
as possible.
On a bare board, have to actually
implement basic I/O
Perhaps at the port level
Basically compiler includes an O/S
Storage Management
Stack Allocation
Heap Allocation
Controlled Allocation
Automatic Garbage
Collection
Stack Management
Stack must be allocated for each task in the
program
Usually handled by operating system
Have to worry about size of stack
How/whether to extend it as needed
How/whether to check stack overflow
May or may not be language required
Heap Management
Basic semantics is Allocate/Free
Parameters for allocation
Size in bytes
Alignment (often just use max alignment as
required for example in C by malloc)
Parameters for free
Probably just address (but perhaps size and
aligmnent as well, as in Ada)
Heap Algorithms
Many algorithms available
◦ Free list
◦ Multiple free lists
◦ Binary allocator
Performance considerations
◦ Average case time
◦ Worst case time (real-time critical)
◦ Fragmentation considerations
OS Heap Allocation
Typical O/S provides malloc/free
Malloc takes size in bytes
◦ Returns max aligned address
Free takes address
Optimized for average performance
Often algorithm is not documented
Commit Strategies
Physical Allocation
Virtual Allocation
◦ Storage committed at allocate time
◦ Storage committed at use time
Overflow checking
◦ Indication of out of memory
◦ Difficulties with commit on use
Specialized Strategies
Trade off fragmentation with time
performance.
Fragmentation
◦ Internal, block allocated is larger than
needed by the allocation request
◦ External, storage available, but not
contiguous.
BinaryAllocator Performance
Issues
Internal Fragmentation
◦ Need 40 bytes, get 64 bytes, 24 wasted
External Fragmentation
◦ May have 2 non-contiguous 128 byte
blocks, but cannot allocate 256 bytes
Performance
◦ Bounded (at most K allocation steps)
Controlled Allocation
In C++, constructors automatically allocate
storage, destructors free storage.
In Ada, controlled type Initialize allocates,
Finalize frees storage.
Can be used for other than storage issues,
but 99% of time usage is for allocate/free
of memory
Implementing Controlled Storage
Compiler inserts automatic calls to constructors and
destructors
In GNAT, you can use –gnatG to see this happening in
the expanded code.
Constructors/destructors contain appropriate storage
mgmt calls.
Automatic Garbage Collection
Allocate storage as needed
Free storage automatically when no
longer needed.
◦ Concept of reach-ability
◦ Can garbage collect when non-reachable.
Possibly compact storage
◦ Considerations of adjusting pointers
Determining Blocks in Use
Assume that we can tell what blocks are
currently allocated.
We have certainly starting points
◦ Global and local variables
◦ Register contents
◦ These are called “roots”
Tracing Blocks in Use
Need to find all pointers in blocks in
use, and recursively trace other blocks
in use, following all pointers.
Two approaches
◦ Conservative
◦ Type-Accurate
Conservative Tracing
Conservative Garbage Collection
◦ If it looks like a pointer, assume it is
◦ Will never release used storage
◦ May hold onto garbage
Type-Accurate Garbage Collection
◦ Know where pointers are
◦ Trace only pointers, knowing types
Further Steps in GC
Once all blocks in use are traced
Free all remaining blocks
Possibly compact blocks in use
Adjust pointers if compaction
◦ Requires type accurate tracing
◦ Since only pointers must be adjusted
◦ Eliminates external fragmentation
Concerns with GC
Stop the world and GC
◦ Not good for a rocket launch!
◦ Or even for an ATM/Web use if too slow
Parallel garbage collection
◦ GC as you go along
◦ Have a separate processor doing GC
Requires delicate syncrhonization
Reference Counts
Each block has a count of number of pointers
to the block.
Copying a pointer increments count
Destroying a pointer decrements count
If count goes to zero, free block
But cycles can be complete garbage and never
freed.
Tasking
Might be done with explicit library
◦ E.g. use of POSIX threads in C
◦ No special compiler considerations
◦ Except for synchronization issues
E.g. when stuff can be held in registers
VOLATILE/ATOMIC considerations
POSIX/Threads is almost standard
◦ Not perfect, some variations
◦ Not always completely implemented yet
Language Tasking Constructs
Threads in Java
Tasks in Ada
Built in defined semantics
May be more or less precisely defined
with respect to
◦ Priority handling
◦ Guaranteed performance
◦ Dispatching issues (e.g. time slicing?)
Implementing Tasking
Map tasks onto OS threads
1/1 (each task is a thread)
Many/1 (multiple tasks to a thread)
All/1 (don’t need OS threads)
Cannot map tasks to processes
Because of address space issues
May be difficult to get exact semantic
equivalence.
Implementations of Exception Handling
C++, Java and Ada share same same
basic model of exceptions.
Replacement semantics
Raise/Throw an exception
Abandons current execution
Strips stack frames
Till exception is handled/caught
Calendar/Time Issues
Match of semantics
Time changes, daylight saving
Formats of dates etc.
Use for delays, alarms
Resolution
Special target dependent capabilities
E.g. high resolution timer on NT
Certification Issues
Safety-Critical certification
Requires complete testing
And documentation of process
For a run-time
Must provide testing materials
Certify the process
One approach: no run-time at all!
Applies to OS as well
WRS new certifiable kernel
In preparation for a follow up of this course
you will install the following Programming
Languages and tools on your Laptops:
Java, Eclipse, C++, C#, Visual Studio, PHP,
Microsoft Access, Oracle, Star UML,
NetBeans, Microsoft Visio, Oracle,
ArchiMate and ArisExpress
Dr. Joe Essien