Technology
How to think like a computer?
.png&w=3840&q=75)
Unlocking Programming Paradigms
The process of learning a new programming language (such as Python or C++) is frequently simply a matter of learning vocabulary. However, a new Programming Paradigm is a new way of thinking. A paradigm is not simply a way of coding, it is a basic philosophy regarding the way to solve problems. It determines the way you set up your code and the way you instruct the computer to work. Although the number of paradigms is great, there are three large paradigms that influence the software world.
- Procedural
- Functional
- Logic-Based
These various mindsets can be divided.
1. Procedural Programming - The Recipe.
This is the most logical paradigm to a beginner as it resembles how human beings are usually inclined towards giving instructions.
The Philosophy - Do this, and then that. In procedural programming, the code is viewed as a sequence of steps in order to modify the state of the computer. It is based on a lot of variables, loops and conditional statements.
The Analogy - Consider it as a Cooking Recipe.
- Take two eggs.
- Crack them into a bowl.
- Whisk until smooth.
- If pan is hot, pour eggs.
You are literally instructing the machine on the process through which the result is attained.
Examples - C, Pascal, BASIC, Go. Best - Systems programming, embedded systems, and general-purpose scripting with performance and explicit control being important concerns.
2. Functional Programming - The Math Equation.
In this paradigm, as we have already mentioned in earlier posts, computation is the assessment of mathematical functions.
The Philosophy - "This is that." In functional programming, change of state (such as the increment of a variable x = x + 1) is not emphasized rather, in functional programming, emphasis is placed on immutability and on pure functions. You feed it into a pipe of transformations that have no side effects.
The Analogy - It was the same as an Assembly Line. On one end there is an input of raw material (Data). It enters into sequences of machines (Functions). It is washed in Machine A, painted in Machine B, and packed in Machine C. The machines remain the same, they only take what they are fed to do.
Examples - Haskell, Lisp, Elixir, F#. Best - This is best used with data processing, concurrent systems and high-reliability applications where bugs are extremely important to avoid.
3. Logic-Based Programming - The Puzzle Solver.
This is the paradigm of alien to most developers since it does not entail instructing the computer on what to do at all.
The Philosophy - " These are the facts, find the answer. In logic programming, you specify a collection of facts (Socrates is a man), and a collection of rules (All men are mortal). Then you pose the question to the computer (Is Socrates mortal?), and the system based on its internal logic engine will deduce the answer. You state the logic, and not the flow of control.
The Comparison - Imagine it as a Detective or a Database. You are not going to tell the detective how to walk or talk. You provide them with the hints (facts) and the rules (regulations) and they solve the case of who killed by the limitations.
Examples - Prolog, Datalog. Best - Artificial Intelligence (AI), expert systems, natural language processing, and solving complex constraints (such as booking flights).
Conclusion
The Right Tool to the Job. The majority of the modern languages (such as Python, Java, and JavaScript) are, in fact, Multi-Paradigm. These styles are mixed and matched by them.
But it is knowledge of the pure forms of these paradigms which makes you a stronger engineer. It teaches you that the solution to a problem is not always a list of steps (Procedural), but rather some mathematical transformation (Functional) or a collection of logical constraints (Logic).
Test Your Knowledge!
Click the button below to generate an AI-powered quiz based on this article.
Did you enjoy this article?
Show your appreciation by giving it a like!
Conversation (0)
Cite This Article
Generating...


