11 important Programming Paradigm topics by Kenno

11 important Programming Paradigm topics by Kenno

An attempt to comprehend different patterns of programming and it's significance.

Again… the same incident happened again!…what do I do?... publishing this article of Kenno🐛

1. What

Programming paradigms are a way to classify programming languages based on their features.

Different types of solutions can be used to address a particular problem and Programming paradigms are nothing more than many types of methods or patterns to solve a problem.

Finding the best and most appropriate method to solve a problem becomes easier when we properly understand the programming paradigms. Unnecessary complexities of a program are eliminated when a paradigm approach is followed.

There are primarily 28 programming paradigms and associated sub-paradigms, according to Wikipedia. Out of these paradigms, the ones we'll be discussing in this post are declarative, imperative, procedural, functional, object-oriented, logic, structured, and parallel programming paradigms.

Programming paradigms.png

2. Essential Concepts

The discussion on the programming paradigm will be more interesting if we first go through these essential concepts. These concepts are pretty much self-explanatory, hence they do not need further explanation. Although some concepts may not be relevant for this particular post, but I included them anyway because they might be useful in the upcoming posts.

  • In neuropsychology, linguistics, and the philosophy of language, a natural language or ordinary language is any language that has evolved naturally in humans through use and repetition without conscious planning or premeditation.

  • In logic, mathematics, computer science, and linguistics, a formal language consists of words whose letters are taken from an alphabet and are well-formed according to a specific set of rules.

  • Artificial languages are languages of a typically very limited size which emerge either in computer simulations between artificial agents, robot interactions or controlled psychological experiments with humans.

  • A constructed language (sometimes called a conlang)is a language whose phonology, grammar, and vocabulary, instead of having developed naturally, are consciously devised for some purpose, which may include being devised for a work of fiction.

  • The essence of abstractionis preserving information that is relevant in a given context, and forgetting information that is irrelevant in that context. ~ John V. Guttag

  • In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A device that executes instructions described by that ISA, such as a central processing unit (CPU), is called an implementation.

  • In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated.

  • In mathematics and computer science, an algorithmis a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation.

  • In information technology and computer science, a system is described as stateful if it is designed to remember preceding events or user interactions; the remembered information is called the stateof the system.

  • In computer science, separation of concerns is a design principle for separating a computer program into distinct sections.

  • A computer language is a formal language used to communicate with a computer.

  • A programming language consists of a grammar/syntax plus an execution model. The execution model specifies the behavior of elements of the language.

  • In computability theory, a system of data-manipulation rules is said to be Turing-complete or computationally universal if it can be used to simulate any Turing machine.

  • In computer science, an operation, function or expression is said to have a side effect if it modifies some state variable value(s) outside its local environment, which is to say if it has any observable effect other than its primary effect of returning a value to the invoker of the operation.

  • Spaghetti code is a pejorative phrase for unstructured and difficult-to-maintain source code. Spaghetti code can be caused by several factors, such as volatile project requirements, lack of programming style rules, and software engineers with insufficient ability or experience.

  • A computer program is a sequence or set of instructions in a programming language for a computer to execute.

  • In computer programming, a block or code block or block of code is a lexical structure of source code which is grouped together. Blocks consist of one or more declarations and statements.

  • In computer programming, a subroutineis a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.

  • In programming language design, a first-class citizen (also type, object, entity, or value) in a given programming language is an entity which supports all the operations generally available to other entities. These operations typically include being passed as an argument, returned from a function, and assigned to a variable.

  • In computer programming, a pure function is a function that has the following properties: the function return values are identical for identical arguments, and the function application has no side effects. Thus a pure function is a computational analogue of a mathematical function.

3. Declarative Programming Paradigm

In computer science, declarative programming is a programming paradigm—a style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow.

It only declares the logic of a solution to a problem without mentioning the precise steps that must be taken to implement the solution. Let's consider the following problem:

From a student’s database, we need to retrieve all the students who scored greater than 60% and less than 70% in physics.

If we want to solve this problem using the declarative method, we would just input what (end result) we want in the application or system. We don't need to tell the application or system step by step how it should accomplish the task. It is end-result oriented.

4. Imperative Programming Paradigm

In computer science, imperative programming is a programming paradigm of software that uses statements that change a program's state.

Solving the same problem mentioned above using the imperative method would require us to tell the application or system step-by-step how it should accomplish the task. It is process oriented.

5. Procedural Programming Paradigm

Procedural programming is a programming paradigm, derived from imperative programming, based on the concept of the procedure call.

Basically both imperative and procedural paradigms are the same. However, in procedural programming program instructions are divided into procedures which are different from functions and have side effects.

Procedural Programming is supported by FORTRAN, ALGOL, COBOL, PL/I, BASIC, Pascal and C.

6. Object-oriented Programming Paradigm

Object-oriented programming(OOP) is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).

An object is an instance of a class (Class: Human Object: Alex) and contains data and instructions. A class simply classifies or explains an object. And objects can be used to represent real-world things like students, employees, departments, cars, etc. Some mentionable features of this paradigm are encapsulation, abstraction, inheritance, and polymorphism. I’ll be talking about OOP in a separate and in-depth post in the future.

Object-oriented Programming is supported by Java, C++, C#, Python, R, PHP, Visual Basic.NET, JavaScript, Ruby, Perl, SIMSCRIPT, Object Pascal, Objective-C, Dart, Swift, Scala, Kotlin, Common Lisp, MATLAB, and Smalltalk.

7. Functional Programming Paradigm

In computer science, functional programmingis a programming paradigm where programs are constructed by applying and composing functions.

A function is created by packaging all the instructions to perform a specific task. In this paradigm, generally different functions are composed to perform different tasks and don’t have side effects. Functions are treated as first-class citizens and sometimes pure functions.

Functional Programming is supported by Clojure, Common Lisp, Elm, Elixir, Erlang, F#, Haskell, Idris, JavaScript, Kotlin, OCaml, PureScript, Python, Racket, Scala, Wolfram.

8. Logic Programming Paradigm

Logic programming is a programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem domain.

In this paradigm, a problem is solved using predefined facts and rules rather than a set of instructions. Observe the following example:

Fact1 : Tweety is a bird.

Fact2 : Tommy is a dog.

Rule1 : All birds can fly.

Rule2 : All dogs can not fly.

Query1 : Can Tweety fly ?

Result1 : yes.

Query2 : Can Tommy fly ?

Result2 : no.

Query3 : Who can fly ?

Result3 : Tweety.

Logic programming is supported by Prolog, Alice, ASP, Absys, Ciao, Datalog ALF.

9. Structured Programming Paradigm

Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection (if/then/else) and repetition (while and for), block structures, and subroutines.

It is regarded as the first significant programming paradigm to arrive in the late 1950s with the introduction of ALGOL.

Using this approach, the control flow of a program can be interrupted or repeated as per the requirements using conditional statements or loops. It can produce spaghetti code if it is not properly formatted using blocks of code, which improves the readability and maintainability.

A graphical representation of the structured program theorem:

Structured program patterns.png
By CC0, Link

10. Parallel Computing Paradigm

Parallel computing is a type of computation in which many calculations or processes are carried out simultaneously. Large problems can often be divided into smaller ones, which can then be solved at the same time.

It always makes sense to break gigantic tasks into smaller manageable chunks to save resources. Even though parallel computing and concurrent computing are closely related and these terms are often used interchangeably, they are not the same. We can have parallelism without concurrency and concurrency without parallelism.

Parallel computing is supported by C, C++, C#, Go.

11. Multi-paradigm

If a programming language supports more than one paradigm, it is considered a multi-paradigm programming language. A multi-paradigm programming language provides a framework in which we can flexibly blend different styles as per our needs. Since a single paradigm approach to solving real-world problems is not always the easiest or most efficient way, the multi-paradigm approach allows us to use the best tools from different paradigms.

A nice comparison of multi-paradigm programming languages can be found here.

In Programming Paradigms for Dummies Peter Van Roy, a Computing Science and Engineering professor talks about declarative concurrency, functional reactive programming, discrete synchronous programming, and constraint programming which according to the professor are paradigms that greatly simplify concurrent programming with respect to mainstream languages.

Hello there 👋 Thank you very much for taking the time to read this post🙏 Please feel free to share your ideas, recommendations, comments, questions and I'll forward them to "Kenno". Also, if you've written something or have a reference on the same subject, kindly share it with me and I'll do my best to read it. I'll catch up with you later🙂