Programming Paradigm

Programming

A paradigm is a school of thought or model with distinct features, frameworks, patterns, and style that aid in the solution of a certain problem. Psychology, sociology, etymology, computer science, and other fields all employ paradigms. New programming languages evolve from existing languages in the field of computer science, adding, removing, and combining features in novel ways.

The languages may follow a single paradigm or be a hybrid of several paradigms. Programming languages are tools, and not every tool is suitable for every task. Some tasks are easier to complete in terms of functionality. Some are clearly more suited to Object-Oriented programming than others. When you employ constraint solving or pattern matching, you can make things easier for yourself.


Programming Paradigms

Let us go on a whirlwind tour of 4 different programming paradigms – Procedural, Object-Oriented, Functional and Logical. This article will give you a better understanding of the various programming paradigms.

1. Procedural Programming

Procedural programming is another name for procedural programming. It’s a programming paradigm based on procedure calls. In which statements are organized into processes (also known as subroutines or functions). Procedural programming languages are sometimes top-down languages since they are a series of instructions that tell the machine what to do step by step. The majority of early programming languages were procedural.

Examples of Fortran C and Cobol. Here is a sample code in COBOL.

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
 DISPLAY ‘Hello World!’.
 STOP RUN.

2. Logical Programming

Logical programming is a computer programming paradigm based on mathematical logic, in which program statements convey facts and rules concerning system problems. Logic clauses with a head and a body write rules. They also take a declarative approach rather than an imperative one. But what exactly does that imply?

To understand how logical programming may solve a problem, you must first grasp the building elements Facts and Rules.

Let’s look at the distinction between declarative and imperative programming.

Assume you stroll into your favorite coffee shop and want to order a cup of coffee.

The imperative approach will be:

  • Enter the coffee shop
  • Queue in the line and wait for the barista asking you for your order
  • Order
  • Yes, for takeaway, please
  • Pay
  • Present your loyalty card to collect points
  • Take your order and walk away

The declarative approach:

  • A large latte for takeaway, please
Rather than giving step-by-step instruction (which is mandatory), you tell the system what you need and let it figure out solution for you (declarative).
It is the most well-known logical programming language, and it adheres to the Logical paradigm.
This has had huge impact in the areas of theorem proving, expert systems, natural language processing, and artificial intelligence in general (particularly IBM’s Watson2).
Prolog has two main components, one for expressing data and the other for querying it, similar to SQL. 
Logic is responsible for the core constructs of logical programming, such as terms and sentences. 
There are three fundamental assertions:
  • Facts are fundamental assertions about the problem domain (e.g. “Socrates is a man”)
  • Rules are inferences about facts in the domain (e.g. “All men are mortal.”)
  • Queries are questions about that domain (e.g. “Is Socrates mortal?”)

3. Functional Programming

Functional programming is a programming paradigm in which the structure and elements of computer programs are specific. You prevent changing-state and mutable data by treating computation as an evaluation of mathematical functions.

Pure functions are ones that take an argument list as input and return a value as output. You may now believe that all functions are pure because they all take values and return a value.

If a function, for example, relies on the contents of a global variable or a class member, it is not pure. In such circumstances, the function’s return value is not wholly dependent on the list of arguments provided as input, and it may also have unintended consequences. So, what exactly do you mean when you say “side effect”? A side effect is a change in an application’s state that is visible outside of the called function but not in its return value. Consider the following scenario: Changing any external variable or object property, such as a global variable or a parent function scope chain variable.

4. Object-Oriented Programming(OO):

All real-world entities are represented by Classes in this framework. Because objects are instances of classes, they individually contain a state and behavior. State refers to the object’s fields and attributes, whereas behavior refers to what you do with the object’s state and is represented by methods. Messages are used to communicate between objects.


This article should definitely help you understand the nuances of the evolution of programming languages, and how each paradigm has contributed to the nurturing and growth of programming languages in the best interest of the programming fraternity, after you’ve completed a tour of programming paradigms.

X-Soft

X-Soft is an established player in the IT market committed to providing excellent solutions for Web/ Mobile (iOS, Android, Web) around the globe. Namely, we are a team of professional web and mobile developers with 10+ years of experience.

Leave a Reply

Leave a Reply

Your email address will not be published.