Overview of the concepts of programming paradigms for beginners..
A theory most students in the field of Information Technology do not fully comprehend is the concepts of “Programming”. Programming is todays leading syllable in edge of every professional body from medicine, engineering, human resource, visual arts, music etc. but,
What is a Programming Paradigm?
It is a collection of distinct set of programming concepts or thought patterns in the field of software programming or development.
Didn’t get it? I know, cuz I didn’t either, at least that’s what Google says.
Now put this in mind, a programming paradigm is just a style of programming or conceptual idea, you use when you write a program under various criteria. There are lots of programming languages that are well-known but all of them need to follow some strategy. So, with that in mind let’s get to the real question,
What are the Programming Paradigms?
This is the first paradigm you will have to learn before going on to the rest as this will cover the basic knowledge on conceptual programming.
In imperative paradigms, you will write computer programs by telling the computer how to solve the program, providing the method, as well as telling it what to solve, providing the data. The Imperative Paradigm has two types of sub-paradigms namely:
i) Procedure Oriented Programming
The what? As the name states, it is a procedural method where, you will write methods that would run operations based on the data you provide.
The when? Most programs written in POP are single-file applications, meaning you practically can’t build large applications in this paradigm.
Example: Calculate the sum of first 100 numbers in Python.
>> SUM of first 100 numbers is: 5050
ii) Object Oriented Programming
The what? In OOP, you will write both the methods and the data inside classes and objects. Those are the two main aspects used when writing OO code followed by the 04 major principles, Encapsulation, Inheritance, Abstraction and Polymorphism. This has several advantages over procedural programming:
- OOP is faster and easier to execute
- OOP provides a clear structure for the programs
- OOP avoids repeatable codes which makes the code easier to maintain, modify and debug
- OOP makes it possible to create full reusable applications with less code and shorter development time
So, what’s the big deal in using the complex OOP paradigm when we could use a procedural paradigm?
The when? Believe me, nobody would stop you from writing your programs in one extremely long file with hundreds of functions and thousands of lines of code, that would consume your invaluable time testing and debugging.
If you, for once without being stubborn, follow the principles of object-oriented programming you will be able to produce reusable, maintainable, scalable clean code which would be very easy in the case of testing and debugging.
Example: using Java
>> Max speed is 320
This paradigm will take you to another level so get ready to collapse your fully functional innocent minds.
Let’s go over the prerequisites first,
- Of course you need to have some knowledge of imperative programming paradigms (C, C++, Python, Java, CSS) any of these will do.
- You should know some basic theory of programming languages so you should know what types are there and how they work, how evaluate of expressions wok and what are the difference between a compiler and interpreters.
In declarative programming, you only tell the computer what to do providing the data, while in imperative programming you tell the how and what both. This paradigm is designed to build complex program algorithms with human readable code that is easy to understand compared to imperative languages.
Declarative programming is, currently, the dominant paradigm of an extensive and diverse set of domains such as databases, templating and configuration management.
i) Functional Programming
The what? The concept of functional programming has been around for a long time, but it is currently enjoying a comeback. It is mostly used to get rid of the issues which come up with concurrency.
In-depth Analysis. The functions used here are not similar to the functions in contrast to the imperative paradigm, where their values are based on arguments, order of evaluation and can also have side effects (change of state). Functional programming languages always uses pure functions by avoiding shared state, mutable data, and side-effects.
A pure function will have no side-effects meaning, for the same input it will always provide the same output. A program in a functional programming language is a pure-function itself.
A functional program in general are easier to verify and that is a huge part of functional programming since we can mathematically prove the correctness of our algorithms.
The when? In my opinion, they are suitable in two main things: Game AIs and mathematical computations. Game AIs is because of its nice list manipulations while mathematical computations is because of its syntax.
Example: calculate the sum of an array of a list of numbers
Functional Programming using Haskell
in comparison with Imperative Programming using C
ii) Logic Programming
The what? As the name states, this programming paradigm relies on the logical behavioral concepts of data by controlling how facts and rules are expressed rather than only mathematical functions. The previous programming paradigms used a structured control flow on how to evaluate function calls on one another and depict when to execute, but the logic paradigm uses its predicated logic clauses also known as logic rules .
The when? In my opinion, the most used logic programming language is “Prolog”, which has been around for 50 years. Prolog is widely used in,
- NLP (Neuro-Linguistic Programming) particularly in syntax and computational semantics
- Expert Systems
- Artificial Intelligence
- Machine Learning
- Deductive databases
- Symbolic computation; i.e. calculus
- Parsing, etc.
I will not explain any of the above uses due to its complexity since this blog is for beginners, but you’ll need to understand a practical scenario so follow the simple example I made below. You can do it yourself in SWI-Prolog if your a programming enthusiast.
Prolog IDLE Output?- studies(John, X).
?- teaches(Mary, X).
?- professor(Mary, John).
The facts are known as knowledge banks.
The rules creates relationships between the facts meaning, when we run a query, the prolog will read the facts along with the rules to throw an output. It’s like they talk with each other.
So in contrast, rules and facts used in the logic paradigm are similar to methods & data used in the imperative paradigm except that the two are read and computed under different conceptual patterns also known as “Paradigms”.
Therefore I will conclude this blog grasping the theory of programming paradigms and I hope you have stayed with me till the end of this article. To know more about each programming paradigm, visit my publication in Programming Paradigms. Apologies, if you read this blog before I published the other articles.