Programming Methodologies

Programming Methodologies

In this article, I am going to discuss Programming Methodologies in detail. Please read our previous article where we discussed Different Types of Applications in detail. At the end of this article, you will understand mostly What are Monolithic Programming, what are Modular/ Procedural programming, and what is Object-Oriented Programming in detail.

Programming Methodologies

The programming paradigms are the styles/methodologies of writing the code in a program. Various programming styles have been adopted depending upon the requirements. There have been different styles used since the beginning of programming languages, and we will explore a few well-known ways in this article.

  1. Monolithic Programming.
  2. Modular/ Procedural.
  3. Object-Oriented.

In today’s era, we are following an Object-oriented programming style but at the beginning, we were following the monolithic approach so let’s see what changes have occurred between them one by one.

Monolithic Programming:

In monolithic programming, the entire program code is present in a single block without any division of code into functions. Monolithic programming is defined as writing a whole program in a single function that is in the main function. A single individual can write and maintain this style of programming, much as a single artist can produce a painting. For example: Here in this example, we have written a sample code in Monolithic Programming style.

static void Main(string[] args)
{
    int i, n;
    bool IsPrime = true;
    Console.WriteLine("Enter a Positive Integer");
    n = Convert.ToInt32(Console.ReadLine());

    //0 and 1 are not prime numbers
    if(n == 0 || n==1)
    {
        IsPrime = false;
    }
    else
    {
        for(i=2; i <= n/2; ++i)
        {
            if(n % i == 0)
            {
                IsPrime = false;
                break;
            }
        }
    }

    if(IsPrime)
    {
        Console.WriteLine(n + " is a Prime Number");
    }
    else
    {
        Console.WriteLine(n + " is not a Prime Number");
    }
}
Benefits
  1. It defines the programming language and how it works.
  2. It is easy and faster to code in a monolithic paradigm.
  3. The simplicity of the code is the biggest advantage.
Disadvantages of Monolithic Programming style:
  1. The program seems to be very large and complex.
  2. Debugging, testing and maintenance of a program are very difficult.
  3. Only one person can write a program at a time. As a result, project development might take an excessive amount of time. The code cannot be divided into segments; hence the development becomes difficult.
  4. In monolithic programming, the data and the instructions are present in a single block and hence the code becomes messy and lengthy.
  5. Redundancy or repetition of the same code at multiple places is a big disadvantage.
  6. Reusability of code is not possible.
Modular/ Procedural Programming:

In this programming style, the code is written in separate blocks and not in a single block that can be used in the program whenever require without writing the entire piece of code again. Here, a particular set of code is present in the form of functions or modules that can be used wherever required. Therefore, it is called modular programming. The most popular programming language in modular programming is the C language.

Modular programming refers to the division of a program into a number of functional pieces. If the main program is separated into sub-programs, we may code each sub-module separately and then integrate them into a single unit. Individual modules of this type are referred to as functions. For example: Here in this example, we have written a sample code in Modular/ Procedural style.

static void Main(string[] args)
{
    int n;
    Console.WriteLine("Enter a Positive Integer");
    n = Convert.ToInt32(Console.ReadLine());
    
    bool isPrime = IsPrime(n);

    if (isPrime)
    {
        Console.WriteLine(n + " is a Prime Number");
    }
    else
    {
        Console.WriteLine(n + " is not a Prime Number");
    }
}

private static bool IsPrime(int n)
{
    bool IsPrime = true;
    //0 and 1 are not prime numbers
    if (n == 0 || n == 1)
    {
        IsPrime = false;
    }
    else
    {
        for (int i = 2; i <= n / 2; ++i)
        {
            if (n % i == 0)
            {
                IsPrime = false;
                break;
            }
        }
    }
    return IsPrime;
}
Advantages of modular programming include:
  • It allows easy development of software and application by splitting down a program into smaller programs to execute a variety of tasks.
  • It increases the readability of code and makes it easier to understand the code.
  • It increases the reusability of code so that a particular piece of code can be used multiple times in a program whenever required.
  • It can be used to write bigger and more complex programs.
  • A team of programmers can work simultaneously and hence big projects can be done easily.
  • It is easy to understand the program.
  • Debugging and maintenance become easy.

Example: Suppose there is an event organized in college that involves a lot of work like making arrangements, so you can divide the work among different teams and the event can be managed easily. Similarly, the entire work(code) is divided among different functions and the program is executed easily.

Importance of the main function: The main function is the manager of the entire code of the program, it manages which block of code is to be executed and when. It is similar to a manager in a shop who manages all the work done by different people in business.

Classes in Object-Oriented Programming
  1. Class – Class is a way of writing organized and structured code where the data and its associated function are encapsulated together within the class.
  2. The objects can be made of class type and can be used to perform various functions.
  3. The way of programming using classes is called the object-oriented programming method.
Object-Oriented Programming:

In OOPs, the code is written in the form of classes that contains different data members and member functions, the data, and their associated functions are grouped together. The objects can also be created by using class type.

We know in the modular approach we have data and functions as separate entities i.e. Functions can use the data from outside. But in an Object-Oriented style, we can have data and function together as one entity. This entity is called Class and we have created multiple instances of a class called Objects. For example: Here in this example, we have written a sample code in Object-Oriented style.

//Car is a class
class Car
{
    string Name;
    int Speed;
    int Weight;

    void Break()
    {
    }

    void SlowDown()
    {
    }

    static void Main(string[] args)
    {
        //ford is an object
        Car ford = new Car();
    }
}
Advantages of Object-Oriented Programming:
  1. We can build the programs from standard working modules that communicate with one another, rather than having to start writing the code from scratch which leads to saving development time and higher productivity.
  2. OOP language allows breaking the program into bit-sized problems that can be solved easily (one object at a time).
  3. OOP systems can be easily upgraded from small to large systems.
  4. The new technology promises greater programmer productivity, a better quality of software, and lesser maintenance cost.
  5. In OOPs, the code is distributed on a large scale that shows a higher level of abstraction.
  6. The class contains data and functions so the complexity is within the class, the programmer deals with the entire class.
  7. Reusability of the class within the code and outside the code is a big advantage.
Difference in Paradigms

Paradigms are just a way of writing and organizing the code but the logic and the functionality of the program remains the same.

Example: It is difficult for a person who is running the hotel to handle all the work by himself like cooking the food, serving the food, and washing the dishes, whereas if there is a division of work among people the task becomes easy. We can observe that the task remains the same but when it is handled separately by a different person, the entire work is carried out easily. Similarly, when the code is divided among functions or classes, its execution becomes easy.

In the next article, I am going to discuss Algorithms, Pseudocode, Programs, and Flowcharts in detail. Here, in this article, I try to explain Programming Methodologies in detail and I hope you enjoy this Programming Methodologies article.

Leave a Reply

Your email address will not be published.