IT Unit 1 Module 3
Programming Paradigms can be used to group different Programming languages.
A programming paradigm is an approach to solve problems using some programming. There are lots of
programming languages that are known but all of them need to follow some strategy when they are
implemented and this methodology/strategy is paradigms.
There are 2 main subdivisions and these are each further broken down.
Imperative Programming is a type of programming paradigm that describes how the program executes.
Developers are more concerned with how to get an answer step by step. It comprises the sequence of
command imperatives. In this, the order of execution is very important Fortran, Java, C, C+
+ programming languages are examples of imperative programming.
Declarative Programming as the name suggests is a type of programming paradigm that describes what
programs to be executed. Developers are more concerned with the answer that is received. In simple
words, it mainly focuses on end result. It expresses the logic of computation. Miranda, Erlang, Haskell,
Prolog are a few popular examples of declarative programming.
AI SUMMARY
Imperative programming focuses on how to achieve a result using explicit, step-by-step commands,
managing state changes, and using loops/conditionals. Declarative programming focuses on what the
desired result is, allowing the system to determine the steps, often using functional or logical
expressions. Imperative is like a recipe (steps), while declarative is like ordering from a menu (desired
result)
Programming Paradigms (on syllabus):
Procedural / Imperative
Object Oriented
Functional Programing
Declarative
Procedural
A subset of imperative programming that organizes code into reusable functions, routines, or
subroutines. It promotes modularity, allowing developers to break complex programs into
manageable sections.
Key Characteristics:
o Top-Down Approach: The program design flows from the main function down to
smaller, specialized procedures.
o State Management: Focuses on updating variables and changing the program's
state over time.
o Control Structures: Uses loops, conditionals, and sequence to control flow.
Examples: C, Fortran, Pascal, COBOL, BASIC.
Advantages/Disadvantages: Procedural programming improves code readability and
reusability. However, it can become complex and difficult to manage in large-scale
applications compared to object-oriented programming
Object Oriented
Object-Oriented Programming (OOP) is a paradigm based on organizing software around data—
or "objects"—rather than functions and logic. Objects, which represent real-world entities,
encapsulate both data (fields/attributes) and behavior (methods). It emphasizes modularity,
code reusability, and easier maintenance, making it ideal for complex, large-scale applications
Common languages that support the OOP paradigm include Java, Python, C++, C#, JavaScript,
and Ruby.
The Real-World Example: A Car
Imagine building a program to manage a fleet of cars. In a non-OOP, procedural
approach, you might have separate lists of data and functions scattered throughout your
code. In OOP, you bundle the related data and behaviors into a single unit: A Car object.
Class (Blueprint): The Car class is the blueprint or template that defines the common
properties and behaviors of all cars.
Objects (Instances): Specific, individual cars are objects created from this class. For
example:
o my_car (a blue BMW manufactured in 2019)
o rental_car (a red Audi from 2017)
Properties (Attributes): The data that describes the object is called its properties or
attributes. A Car class would have properties like:
o color
o make
o model
o speed
Behaviors (Methods): The actions an object can perform are called methods. A Car class
would have methods like:
o startEngine()
o accelerate()
o brake()
o honk()
Benefits of OOP
o Modularity: Code is organized into self-contained objects.
o Reusability: Inheritance allows developers to reuse code.
o Maintainability: Easier to update and debug complex software.
o Security: Data hiding through encapsulation protects data from unauthorized access
Functional Programing
Classified as Declarative.
Functional programming is based on mathematical functions. Some of the popular functional
programming languages include: Lisp, Python, Erlang, Haskell, Clojure
Functional programming languages are designed on the concept of mathematical functions that
use conditional expressions and recursion to perform computation.
Functional programming languages do not support flow Controls like loop statements and
conditional statements like If-Else and Switch Statements. They directly use the functions and
functional calls
They do not modify any arguments or local/global variables or input/output streams. Later
property is called immutability. The pure function's only result is the value it returns.
Example of the Pure Function
sum(x, y) // sum is function taking x and y as arguments
return x + y // sum is returning sum of x and y without changing them
Functional Programming is used in situations where we have to perform lots of different
operations on the same set of data.