Programming Paradigm

Programming Paradigm

Hello it me again😊 trying to help beginners understand some programming jargons. Remember in my previous article Starting Backend Development, I ended by saying “The best way to start your backend development path is to learn a programming or a scripting language”. In this blog post I will be writing on the classification of programming languages based on their features.

This blog post will make you understand what programmers are talking about when they say “functional programming” or “Object-Oriented programming (OOP)”

Programming paradigm: What is it? 🤔

Programming paradigms are ways to classify programming languages based on their features. Each paradigm consists of certain structures, features, and opinions about how common programming problems should be tackled.

What a Programming Paradigm Is Not?

Programming paradigms are neither tools or languages.

__ Programming Paradigm vs Programming Language__
A paradigm cannot be used to built any software. They are just beliefs and principles that many people have embraced, followed, and developed.

Programming languages aren't always tied to a specific paradigm. There are also "multi-paradigm" languages, meaning you can adapt your code to fit a certain paradigm or another (JavaScript and Python are good examples).

Why should I care?

Well just for knowledge sake 😂

Moreover, these terms are used a lot in the coding world, so having a basic understanding will help you better understand other topics as well.

In this section I will be covering 2 popular programming paradigm which are:

  • Functional Programming

  • Object Oriented Programming (OOP)

Other programming paradigm includes; imperative programming, declarative programming, Logic programming and so on. Some programming paradigm can be subdivisions of other programming paradigm.

Functional Programming
In this programming paradigm programs are constructed by applying and composing functions. Here functions are treated as first-class citizens, meaning that they can be assigned to variables, passed as arguments, and returned from other functions, just as any other data type can.

  • Basic Function Syntax:
function name(parameter1, parameter2,….., parameter_n) {
     // code to be executed
  }
  • Function assigned to a variable
let sumFun = function (num1, num2){
      return num1 + num2
  }
  • Function passed as arguments
let averageFun = function (sum, n){
      return sum / n
  }

averageFun(sumFun(2,4),2)
  • Function returned from another function

function root(n){
  return () => sRoot(n)
}

function sRoot(num){
  if (num>= 0){
    return Math.sqrt(num)
  }else{
    return "Can't find square root of negative number"
  }
}

Object Oriented Programming
One of the most popular programming paradigms is object-oriented programming (OOP).

The core concept of OOP is to separate concerns into entities which are coded as objects. Each entity will group a given set of information (properties) and actions (methods) that can be performed by the entity.

OOP makes heavy usage of classes (which are a way of creating new objects starting out from a blueprint or boilerplate that the programmer sets). Objects that are created from a class are called instances.

  • Basic Class Syntax:
class className {
  // class methods
  constructor() {
    // Block of code
  }
  method1() {
     // Block of code
  }
  method2() {
    // Block of code
  }

  ...

  method_n() {
    // Block of code
  }

}

Functional Programming VS Object Oriented Programming

By Petty Books.png

Summary
Apparently, there are different classes of programming languages but we looked at two in this blog post. We also have multi-paradigm languages (python and JavaScript).

This will be my last article for the year. I have two stressful academic months thanks to the ASUU Strike. By next year I would be starting strong 💪🏼