Skip to main content

Different Types of Programming Paradigm

Programming paradigm mainly describes the way in which a particular computer program should be written. According to Wikipedia, it is fundamental style of computer programming.
Basically, different programming languages are designed to follow a particular paradigm or may be multiple paradigms.


Imperative(procedural) Programming Paradigm: 

 -- Imperative programming is a programming paradigm that uses statements that change a program's   state. -- In much the same way that the imperative mood in natural languages expresses commands. -- An imperative program consists of commands for the computer to perform. -- Imperative programs describe the details of HOW the results are to be obtained.--  HOW means describing the Inputs and describing how the Outputs are produced. 

 Examples are: C, C++, Java, PHP, Python, Ruby etc.


  • Popular programming languages are imperative more often than they are any other paradigm . There are two reasons for such popularity:
    1. the imperative paradigm most closely resembles the actual machine itself, so the programmer is much closer to the machine;
    2. because of such closeness, the imperative paradigm was the only one efficient enough for widespread use until recently.
  • Advantages
    • efficient;
    • close to the machine;
    • popular;
    • familiar.
  • Disadvantages
    • The semantics of a program can be complex to understand or prove, because of referential transparency does not hold(due to side effects)
    • Side effects also make debugging harder;
    • Abstration is more limitted than with some paradigms;
    • Order is crucial, which doesn't always suit itself to problems. 

Functional Programming Paradigm:

-- Functional programming is a subset of declarative programming.-- Programs written using this paradigm use functions, blocks of code intended to behave like mathematical functions.-- Functional languages discourage changes in the value of variables through assignment, making a great deal of use of recursion instead.

Examples are : F#, Haskell, Lisp, Python, Ruby, JavaScript etc

 The Functional Programming paradigm views all subprograms as functions in the mathematical sense, they take in arguments and return a single solution.




  • Advantages
    The following are desirable properties of a functional language:
    1. The high level of abstraction, especially when functions are used, supresses many of the details of programming and thus removes the possibility of commiting many classes of errors;
    2. The lack of dependence on assignment operations, allowing programs to be evaluated in many different orders. This evaluation order independence makes function-oriented languages good candidates for programming massively parallel computers;
    3. The absence of assignment operations makes the function-oriented programs much more amenable to mathematical proof and analysis than are imperative programs, because functional programs possess referential transparency.
  • Disadvantages
    1. Perhaps less efficiencey.
    2. Problems involving many variables or a lot of sequential activity are sometimes easier to handle imperatively or with object-oriented programming.


  • Object Oriented Programming Paradigm: 

    -- Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.-- There is significant diversity of OOP languages, but the most popular ones are class-based, meaning that objects are instances of classes, which typically also determine their type.-- In OOP, computer programs are designed by making them out of objects.

    Examples are: C++, C#, Java, PHP, Python

     Features & Benefits
    A new class (called a derived class or subclass) may be derived from another class (called a base class or superclass) by a mechanism called inheritance. The derived class inherits all the features of the base class: its structure and behavior. In addition, the derived class may contain additional state (instance variables), and may exhibit additional behavior (new methods to resond to new messages). Significantly, the derived class can also override behavior corresponding to some of the methods of the base class: there would be a different method to respond to the same message. Also, the inheritance mechanism is allowed even without access to the source code of the base class.
    The ability to use inheritance is the single most distinguishing feature of the OOP paradigm. Inheritance gives OOP its chief benefit over other programming paradigms - relatively easy code reuse and extension without the need to change existing source code.

    The mechanism of modeling a program as a collection of objects of various classes, and furthermore describing many classes as extensions or modifications of other classes, provides a high degree of modularity. 


    Declarative Programming Paradigm:

    • The Declarative Paradigm takes a approach to problem-solving. Various logical assertions about a situation are made, establishing all known facts. Then queries are made. The role of the computer becomes maintaining data and logical deduction.
    • Example: SQL, CSS.
     

     









     
     

    Comments

    Popular posts from this blog

    DFS Performance Measurement

    Completeness DFS is not complete, to convince yourself consider that our search start expanding the left subtree of the root for so long path (maybe infinite) when different choice near the root could lead to a solution, now suppose that the left subtree of the root has no solution, and it is unbounded, then the search will continue going deep infinitely, in this case , we say that DFS is not complete. Optimality  Consider the scenario that there is more than one goal node, and our search decided to first expand the left subtree of the root where there is a solution at a very deep level of this left subtree , in the same time the right subtree of the root has a solution near the root, here comes the non-optimality of DFS that it is not guaranteed that the first goal to find is the optimal one, so we conclude that DFS is not optimal. Time Complexity Consider a state space that is identical to that of BFS, with branching factor b, and we start the search fro...

    Difference between a Singly LinkedList and Doubly LinkedList

    Difference between abstract class and interface in OOP

    Source: Amit Sethi In Interface: > All variables must be public static final. > No constructors. An interface can not be instantiated using the new operator.   > All methods must be public abstract .