Lecture 33:  Programming Language Paradigms

 

Objectives of this lecture

q       Learn the different approaches to programming languages –language paradigms

 

What is a paradigm

q       Paradigm means an approach or a way of reasoning to solve a problem.  In this lecture, we discuss the various programming language paradigms.

 

Procedural Paradigm

q       The most common paradigm is the procedural paradigm which resembles the structure of the computer.  Memory location, assignment and procedures & functions are central to this approach. 

q       It is essentially modeled based on the fetch-decode-execute phases of the instruction cycle. 

q       Languages using this paradigm are called procedural or imperative languages.  FORTRAN, BASIC, Pascal, Ada and C, are all examples of these languages.

 

Object-oriented Paradigm (OOP)

q       The object-oriented paradigm treats data and functions that act on it as a single object or data structure.  Thus, OOP is based on data structure rather than the process or subprograms.

q       An abstract data type called object can be associated with different data types at run time – dynamic binding. 

q       Programming is thus, simplified , because instead of re-writing an existing object for a different data type and a different purpose, we simply modify the object when it is invoked.

q       Another important property of objects is inheritance -- an object can be inherited by other objects, hence can be used by more than one program on a system.

q       The first OOP language, Smalltalk was developed in 1968 and is the model for the OOP paradigm in use today.  Smalltalk is simple and powerful.  Its only drawback is that it is inefficient.

q       C++ is another object –oriented language that was developed in 1985.  C++ is not a “pure” object-oriented language as is Smalltalk, but it fits the paradigm in that its data structures are objects.  In fact C++ is actually a superset of C.

 

q       Another object-oriented language that is gaining enormous popularity is JAVA.  In JAVA, objects in different computer systems can communicated through the networking capability provided by the language.

 

Functional Programming Languages (Application)

q       This approach involves the use of a set of basic functions (called primitives).  Problems are solved by using these basic functions to derive other functions.  Some of the primitive functions may work in parallel, thereby making the process efficient.

Example: Consider evaluating the function

f(x) =2.3x2-7.4 sin x + cos (3.4x)

 

The function f(x) is the algebraic sum of three other functions 2.3x2, 7.4 sin x and cos (3.4x).  Each of these is a function of other function.  For example 2.3x2 is a function consisting of the product of the square of x, a function, and the floating- point number 2.3

 

The following diagram represents this as a black box.

 

 

 

 

 

 

 

 

 

 

 

 

 


In this example, the primitive functions consists of the three floating-point constants and the variables x.

q       A set of primitive functions including arithmetic, logical operations and special functions is described by these types of  languages.  Example of functional programming languages are LISP, APL, HASKEL, scheme etc.

q       A principal property of functional languages is the prohibition of assessment operation.  They use mathematical-styled functions, conditional expressions and recursion.

q       Extensive use of recursion makes looping structures such as while and for loops unnecessary.

 

Declarative Languages

q       This approach involves declaring a set of facts and logical relationships connecting those facts.  Problems are then solved by making use of the facts and the relationships.  Declarative languages are concerned more with “what” to do as opposed to “how” to do it.  This mode of reasoning is called logic paradigm.

q       The most popular declarative language is PROLOG (PROgramming LOGic).  It has wide appeal in artificial intelligence and expert systems.

q       Another well-known declarative language is SNOBOL4 (StriNg Oriented symBOlic Language), developed in 1960.

q       Declarative languages are particularly suitable for database management system. SQL (Structured Quary Language) is another example of declarative language.