Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

CSC 401 – ORGANIZATION OF PROGRAMMING LANGUAGES

WEEK 1 LECTURE
INTRODUCTION TO PROGRAMING LANGUAGES
1.0 INTRODUCTION
Several Programming Languages (PL) have been developed and most of them are in use today. However, some of these PLs have similarity while some
are entirely different from each other. The comparison between the PLs led to categorizing PL into different classes. Organization of Programming
Languages (OPL) is a course on the fundamental principles of programming languages and techniques in programming languages design and
implementation. It handles the programing paradigm and historical pattern of programming. The course elaborates on language structure, data type and
data structure.

2.0 LEARNING OUTCOMES


At the completion of this unit, the students will be able to:
i. understand the evolution of programming languages;
ii. motivations for organization of programming languages;
iii. Programming language paradigms.

3.0 MAIN CONTENT


3.1 Evolution of programming language

1
Evolution of Programming Languages
from 1954 – 2017.

2
3.2 Motivation for organization of programming languages
Programming languages are many and there is need to identify the features of each language while solving problem.
This and some other reasons are the benefits of studying this course. The following are the benefits one stands to
gain for studying organization of programming languages:

1. It promotes easy and fast learning of a new language.


2. Enables one to device better approaches for designing new programming language.
3. Helps one to have a good command of programming languages towards writing better programs.
4. Assists in finding a better ways of expressing ideas or solving problems.
5. It gives good background for choosing appropriate language.
6. It enhances better use of languages that are already known.
7. It brings about an overall advancement in computing.

3.3 Programming language paradigms


Programming paradigm is simply methods or ways in which we write codes to solve different types problems. there
are many paradigms that we can use to write codes. Every programming language has a paradigm or a number of
paradigms that is best suited to it.

Several programming languages have been invented, and a good number of them are actually in use. Compared to natural
languages that developed and evolved independently, programming languages are far more similar to each other because:

✓ different programming languages share the same mathematical foundation (e.g., Boolean algebra, logic);
✓ they provide similar functionality (e.g., arithmetic, logic operations, and text processing);
✓ they are based on the same kind of hardware and instruction sets;
✓ they have common design goals: find languages that make it simple for humans to use and efficient for hardware
to execute;
✓ designers of programming languages share their design experiences.

Some Common Paradigms

You should know these:

• Imperative: Programming with an explicit sequence of commands that update state.

• Declarative: Programming by specifying the result you want, not how to get it.

• Structured: Programming with clean, goto-free, nested control structures.

• Procedural: Imperative programming with procedure calls.

• Functional (Applicative): Programming with function calls that avoid any global state.

• Function-Level (Combinator): Programming with no variables at all.

• Object-Oriented: Programming by defining objects that send messages to each other. Objects have their
own internal (encapsulated) state and public interfaces. Object orientation can be:

3
o Class-based: Objects get state and behavior based on membership in a class.
o Prototype-based: Objects get behavior from a prototype object.
• Event-Driven: Programming with emitters and listeners of asynchronous actions.

• Flow-Driven: Programming processes communicating with each other over predefined channels.

• Logic (Rule-based): Programming by specifying a set of facts and rules. An engine infers the answers to
questions.

• Constraint: Programming by specifying a set of constraints. An engine finds the values that meet the
constraints.

• Aspect-Oriented: Programming cross-cutting concerns applied transparently.

• Reflective: Programming by manipulating the program elements themselves.

• Array: Programming with powerful array operators that usually make loops unnecessary.

Paradigms are not meant to be mutually exclusive; a single program can feature multiple paradigms!

The Most Popular Paradigms


1. Imperative Paradigm
• The language provides statements, such as assignment statements, which explicitly change the state of
the memory of the computer.
• It performs task step by step by changing state. The main focus is on how to achieve the goal.
• The paradigm follows the Von Neumann architecture statements and consist of multiple statements and
variables which calculate and store the result. This concept is illustrated in Figure 1.1 below.
Advantage:
i. Very simple to implement
Disadvantage
i. Less efficient and less productive
ii. Complex problems cannot be solved

Examples: C/C++, Fortran, Basic, COBOL, Java, Python, Pascal, PHP, Ruby, Scala

Simple Imperative Program

Figure 1.1: Sample imperative program


4
Some examples of paradigms that popularize this method of programming are:

The procedural paradigm, object-oriented paradigm, and parallel processing paradigm.

2. Procedural Paradigm
• The procedural paradigm aims at dividing a large program into smaller programs called procedures. The
procedures are also known as functions, methods, or subroutines.
• The function consists of computational steps that directs the computer to perform specific operation. The
function once defined can be called many times in the program to repeat the same operation.
• The function can access and operate upon its own data as well as global data shared by all other functions.
Figure 1.2 illustrates this concept.

Figure 1.2: Sharing of global data by functions

• In this paradigm, the program statements are grouped together based on the functionality needed. For
example, we can group program statements that accepts two numbers as user input, then add these
numbers and return the result value. Function declaration is illustrated in Figure 1.3.

Figure 1.2: Function declaration


• The functions can either be defined into the main program code or outside the main program code. In
order to improve the readability of the program, the function can even be defined in a separate header file
that will be included in the program. Illustration of this concept is shown in Figure 1.3.

5
Figure 1.3: Declaration of function outside the main program

• The program code in the procedural paradigm is purely sequential and it uses a top-down approach.
• Examples of pure procedural paradigm are COBOL, FORTRAN, BASIC, C, ALGOL, and Pascal. Other
programming languages that support procedural paradigm are C++, Java, JavaScript and Python.

Features of Procedural Programming Paradigm


The procedural programming paradigm has some important features. These features define program
organization, sequence of execution and the scope of the variables:

i. Top-down Approach – In this approach, the program execution starts at the top and the program
statements are executed one after the other. However, the programmer has a number of options to
change the program execution by using program flow control statements.
ii. Header File Declaration – The header files offer a convenient way of organizing the program code in
the procedural programming. The header file inclusion statements are declared at the top section of the
program. The header file can contain predefined library functions. For example, in C language, the
stdio.h (header file) contains the standard function declarations for commonly used input and output
function.
iii. Predefined Library Functions - Most procedural programming languages offer extensive library of
defined functions. These library functions are readily available for use in the program code. The
predefined library functions are used to reduce overall development time.
iv. User Defined Library Functions – All procedural programming languages offer programmer option
to write the user defined functions. The user can define these functions to handle some specific
functionality in the program code.
v. Variable Scope - The scope of an identifier determines the accessibility of that identifier within the
program code. For example, a variable declared inside a function block is treated as a local variable.
The local variable can be accessed anywhere inside the function body. Any variable declared outside
the function block is treated as a global variable. The global variable can be accessed anywhere in the
program code by any function, and this makes it vulnerable to changes which may in turn affect the
functionality of the other functions sharing the same data.

6
Advantages of Procedural Paradigm
1. The procedural programming languages are relatively much easier to learn as first programming language
by the beginners.
2. The straightforward program organization makes it ideal choice as a general-purpose language.
3. The procedural programming language such as C language is still being used for many applications.
4. The use of standard library functions bring down significant reduction in the overall development cost
and time.
Disadvantages of Procedural Paradigm
1. The procedural paradigm is not suitable for large and complex software projects.
2. It is difficult to represent the real-world objects realistically in the procedural programming.
3. It is difficult to protect data from inadvertent changes since most data are generally global leading to the
problem of spaghetti code (a source code that is hard to understand because it has no defined structure).
4. Software maintenance is more difficulty in procedural paradigm.
5. Here, functions are considered the most important component of the program. The data are not given
considerable attention.

3. Object-Oriented Paradigm (OOP)


• The object-oriented paradigm attempts to capture or group information, data and related functionality (code)
into structured items known as objects.
• With OOP, the world is viewed as a collection of objects.
• An object could be anything such as an animal, car, person, or house.
• It could also be much more abstract – for example, a customer’s account.
• Each object is responsible for its own data and the operations performed on that data.
• Object interact with each other by sending and receiving messages.
Let’s take a lightbulb as an example of an object. What characteristics does it have?
Wattage: 40 watts
Colour: White
Type: Filament
Connection Type: Screw
Once we have identified the information and actions relating to an object, we can place them into their own class.

Figure 1.4: A Class Template for Lightbulb

7
One of the advantages of the OOP is that once you define a class (i.e. decide what attributes and methods it will
have), it becomes very easy to reuse that class and create hundreds of objects of that class.

We can see that each lightbulb needs a wattage, colour, type and connection type. To create a copy or instance of
a class, we can use a single line of code using the keyword new.
This is called instantiation – “The process of creating an object from a class template”. All the objects created from
the class template will have their own copy of the attributes and methods.
Object-oriented syntax vary from language to language.
The four important fundamental design principles of OOP are i. Encapsulation ii. Inheritance iii. Abstraction, and
iv. Polymorphism. Figure 1.5 illustrates the four design principles with their functions.

Figure 1.5: The four design principles of OOP with their functions

i. Inheritance – In OOP, inheritance simply means deriving one class from another class. The class that is inherited
is called the Super, Base or Parent Class while the class that inherits is called Sub, Child or Derived Class.
Inheritance therefore is the process of acquiring the existing functionality of the Parent Class and adding additional
features and functionality into the Child Class that inherits.
Inheritance basically deals with the reusability of the program code.

Let’s consider the example given below:

8
9
Types of Inheritance

Inheritance That are not allowed by some languages


Hybrid and Multiple inheritances are not allowed by Java. C++ allows the two. Python typically allows multiple
inheritance.

ii. Encapsulation
This is simply the binding together of the data and methods as a single entity. You will recall that lack of data
security is one the major limitations of procedural paradigm. The unrestricted access to data in procedural
paradigm makes data to exposed to changes and this do affect the performance of the functions that share such
data. In OOP paradigm, access is restricted to the methods that belong to the object. The figure below further
illustrates the concept.

10
iii. Polymorphism
• Factually, polymorphism means something that occurs in several different forms. It is derived from a Greek
word meaning “many forms”.
• There are two main types of polymorphism in object-oriented programming:
✓ Static
✓ Dynamic
• A good example of polymorphism is demonstrated in the figure below:

11
iv. Abstraction

The term abstraction in OOP simply means “presenting the simplified view and hiding the complexity”. The
abstraction is frequently used to convey ideas. It does not have a clear applicability to the real life specific objects.

The concept of abstraction is used in the OOP to present a more simplified view of an object by removing the
irrelevant details. The figure below shows how abstraction and encapsulation complement each other.

Advantages of Object-oriented Paradigm


▪ OOP can support large software project.
▪ It offers better data protection.
12
▪ It enhances code reusability.
▪ It gives better representation of the real-world objects.
▪ It gives better software maintenance.
▪ Code modification can be done easily.

OOP DREAM

✓ In the late 90’s, object-oriented programming (OOP) became a dominant programming paradigm.
✓ Now, OOP is considered a bloated system that results in programs that are difficult to maintain, especially
with large projects.
✓ Its creator, Alan Kay, never intended for it to evolve like it has. He insisted that the essential ingredients were
simple message passing, encapsulation, and dynamic binding.
✓ In reality, the very man who coined the term OOP never considered inheritance and subclass polymorphism
to be core concepts.
✓ OOP is now giving way to functional programming, which is considered to produce mush safer, more stable,
and easier to maintain code.

4. Functional Paradigm

Functional programming is designed to handle the symbolic computation and application processing list, and it is
based on mathematical work. The most popular functional programming languages are Python, Lisp, Haskell,
Clojure, Erlang etc.

Functional Programming has two types; those are shown as below:

o Pure Functional Languages: Pure functional language supports only the functional pattern. An example of
the pure functional language is Haskell.
o Impure Functional Language: Impure Functional language supports the prototype of functions and the
programming's imperative style. An example of an impure functional language is LISP.

Characteristics of the Functional Programming Language


Characteristics of the functional programming languages are like as shown below:

o Functional programming languages are designed to perform the functions of mathematical functions. These
functions use conditional expressions and recursion to perform the computation.
o Functional programming supports functions in higher-order and features of lazy evaluation.
o Functional Programming language directly uses the functions and function calls. It does not support the flow
of the controls like statements of the loop, and statements are like the conditional statements such as If-Else
and Switch Statements.
o Object-Oriented Programming supports the Abstraction, Encapsulation, and Polymorphism, just like
functional programming languages support OOPS concepts.

Advantages of the Functional Programming


13
Advantages of the functional programming languages are as shown below:

o Bugs-Free code: Functional Programming language does not support state, so there is no side effect of the
functional programming; hence we can write the error-free code.
o Efficient Programming Language: Functional Programming language has no mutable state, so there is no
state change issue. We can do the program "Functions" to work parallel to "Instruction". This type of code
supports reusability and testability easily.
o Efficiency- Functional Program contains the Independent Units. Independent units run concurrently. Hence
functional programs are more efficient.
o Supports Nested Functions- Nested functions are supported by functional programming.
o Lazy Evaluation- Lazy Functional Constructions are also supported by functional programming such as
Lazy Lists, Lazy Maps, etc.

Functional programming does not have any state, so all the time, there is a need to create new objects to perform the
actions. That's why functional programming needs a large memory space.

Functional programming is used to perform the different operations on the same data set.

The LISP supports artificial intelligence applications such as language processing, Machine learning, Modelling of
speech and vision.

Differences between the Functional Programming and Object-Oriented Programming are:

S/No. Functional Programming Object-Oriented Programming

1. The functional programming language OOP uses mutable data.


supports immutable data.

2. Functional Programming supports the OOP supports the imperative Programming Model.
Declarative Programming Model.

3. Functional Programming focuses on the OOP focuses on the "How we are doing".
"What we are doing".

4. The methods of Functional Programming Methods of the OOP can produce the side-effects.
will not produce any side-effects.

5. Functional Programming follows parallel OOP does not work on parallel programming.
programming.

6. For the flow control, we do function calls & Object-Oriented Programming supports the use of the
function calls with recursion. loops and conditional statements for the flow control.

7. For the iteration of the data collection, Object-Oriented Programming uses the "Loop" concept
functional programming uses the for the iteration of Data collection. For example, For-
"Recursion" concept. each loop in Java

14
8. For functional programming, the execution It is essential for the oop programming to execute the
of statements in the order is not so important. statements in order.

9. Functional Programming supports OOP supports only "Abstraction over Data".


"Abstraction over Data" and "Abstraction
over Behavior".

15

You might also like