A paradigm is a way of looking at something, the closest name to paradigm is a model or a blueprint.
Programming paradigms are different ways in which a program can be visualized and organized.
Each paradigm describes how a computation problem should be tackled. The same programming problem can be viewed and solved differently depending on which paradigm is being used.
A paradigm is not a tool or a programming language and you can't use it to build anything but understanding various paradigms can help you visualize programming problems in different perspectives and make informed decision on which is the most suitable way to tackle the problem.
most widely used programming paradigms
We cannot be able to cover every possible paradigm here, but we will look at the most popular ones.
Imperative programming
Imperative means giving an authoritative command according to the dictionary.
Imperative programming describes how a program operates step by step. Unlike Declarative programming which offers high description of the expected results, imperative programming issues step by step commands on how to achieve the expected results.
One can also argue that any program as a whole is still imperative since in the end, the statements to be executed are arranged in the order of execution.
The most basic example of an imperative language is machine language.
Other languages includes:
- FORTRAN
- ALGOL
- Pascal
- C
- BASIC
Procedural programming
Procedural programming is a type of imperative programming which focuses in grouping statements into procedures i.e functions.
C and C++ are commonly regarded as procedural languages. In these languages, every statement must be organized within one primary function called 'main'. The main function is required and acts as the entry point of the program.
Functional programming
In functional programming, functions are treated like any other datatype.You can assign functions to variables, pass them as arguments to other functions and even return them from other functions.
popular functional languages include:
- Clojure
- Racket
- Haskell
- Elixir
- Common Lisp
Declarative programming
Declarative programming is the opposite of imperative programming.While imperative programming gives commands on how a problem will be tackled, declarative programming avoids dictating how to achieve the results.Declarative languages aims to describes the required results without describing the commands or steps that should be followed to achieve the said results.
types of declarative languages:
-
Query Languages e.g SQL
-
Regular expressions(REGEX)
Object-oriented programming
Object-oriented programming is arguably the most powerful programming paradigm and most programming language though not all supports OOP in one way or another , in fact some languages like java are entirely object-oriented so in such languages everything is viewed as an objects with properties and actions.Python is also one of the most popular object oriented languages though it also supports other paradigms.
in most programming languages including python, OOP is implemented using classes.
In OOP , entities are viewed as object akin to how we view physical objects. Each object will have a set of information known as properties or attributes and actions known as methods associated with it. For example a person in OOP will have attributes such as name , age, gender, buddy etc and methods such as walk, cry , eat etc.
The power of OOP stems from how it creates a logical and intuitive way to simulate real life objects and activities. Objects can have relations with each , for example a person can have a pet associated with him , he can have a buddy which will be an instance of person object.
advantages of OOP
- offers high code reusability through inheritance.
- Viewing programming entities as physical objects is more logical in most cases.
- It is easy to break the work into objects thus allowing us to wok with one object at a time.
- It is more intuitive .
- By using object inheritance we can eliminate redundancy in our code.
- Easy to maintain and modify
- Low development cost.
Disadvantages of OOP
- Steep learning curve.
- We cannot view every programming problem in terms of objects.
- Require's high level of problem solving to create sophisticated objects.