Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between declarative and procedural programming paradigms?

People also ask

What is the difference between declarative paradigm and imperative programming paradigm?

Declarative programming is a paradigm describing WHAT the program does, without explicitly specifying its control flow. Imperative programming is a paradigm describing HOW the program should do something by explicitly specifying each instruction (or statement) step by step, which mutate the program's state.

What are the differences between declarative & Procedural knowledge?

Procedural Knowledge means how a particular thing can be accomplished. While Declarative Knowledge means basic knowledge about something.

What is the difference between procedural and imperative paradigms?

Imperative programming refers to code that is concerned with lower levels of abstraction. Procedural programming is a subset of imperative programming which utilizes subroutines. Functional programming is a subset of declarative programming which utilizes subroutines.

What is procedural programming paradigm?

Procedural programming is a programming paradigm built around the idea that programs are sequences of instructions to be executed. They focus heavily on splitting up programs into named sets of instructions called procedures, analogous to functions.


Imperative

There are several sub-paradigms of the imperative programming paradigm, such as the procedural or the object-oriented programming paradigms.

In the imperative programming paradigm, you describe the algorithm step-by-step, at various degrees of abstraction.

Examples of programming languages which support the procedural paradigm:

  • C (and most other legacy languages)
  • PHP, mostly
  • In some sense, all major languages

Object-Oriented

It typically refers to languages that exhibit a hierarchy of types that inherit both methods and state from base types to derived types, but also includes the unusual prototype-based JavaScript.

Examples of programming languages which support the OO paradigm:

  • Java

Declarative

There are several sub-paradigms of the declarative programming paradigm, such as the functional or the logic programming paradigms.

In the declarative programming paradigm, you describe a result or a goal, and you get it via a "black box". The opposite of imperative.

Examples of programming languages which support the declarative programming paradigm:

  • yacc
  • Treetop
  • SQL
  • Regular Expressions
  • lex
  • XSLT
  • markup, troff, CSS, VHDL

Functional

Functional programming emphasizes the application of functions without side effects and without mutable state. The declarative systems above exhibit certain aspects of functional programming.

Examples of programming languages which support the declarative functional paradigm:

  • Haskell
  • OCaml
  • Scheme
  • Erlang
  • F#
  • Scala

Declarative programming is where you say what you want without having to say how to do it. With procedural programming, you have to specify exact steps to get the result.

For example, SQL is more declarative than procedural, because the queries don't specify steps to produce the result.


Let me give you a real-world example: I need a cup of tea.

Procedural:

  1. Go to kitchen
  2. Get sugar, milk, and tea,
  3. Mix them, and heat over the fire till it boils
  4. Put that in a cup and bring it to me

Declarative:

  1. Get me a cup of tea.

In a procedural language, you define the whole process and provide the steps how to do it. You just provide orders and define how the process will be served.

In a declarative language, you just set the command or order, and let it be on the system how to complete that order. You just need your result without digging into how it should be done.


Procedural Programming :

In procedural programming, when the program starts, it follows a set of instructions. The instructions may change based on some file or memory content, but overall, it doesn't vary widely. the input to the program is typically not from user input in real-time, but rather from a pre-gathered set of data.

Declarative Programming:

In Declarative Event driven programming centralizes around a body of data with optional actions the program can take on it. For example, each "event" in a word processor is any mouse or keyboard (or file) changes that affect the data, the document(s). They need not be performed in any order. Event driven programming takes the form of small programs (event handlers) that all work on a common set of data, so that each small program can use the same data, the document in this example.