Jump to content

Imperative and Declarative: Difference between revisions

From Knowledge Base
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Implicit and Delclarative ==
== Implicit and Declarative ==


Programming paradigms serve as guiding principles, delineating different styles of constructing software code. Among these paradigms, two stand out as foundational: '''imperative programming''' and '''declarative programming'''.
Programming paradigms serve as guiding principles, delineating different styles of constructing software code. Among these paradigms, two stand out as foundational: '''imperative programming''' and '''declarative programming'''.


=== Imperative Programming ===
=== Imperative Programming ===
'''The Classic Paradigm'''
"The Classic Paradigm": Rooted in the earliest days of computing, imperative programming forms the basis of traditional programming languages like Pascal, C and assembly languages. At its core, it revolves around issuing '''explicit commands''' or instructions to direct the computer on how to accomplish a task, reflecting its etymological roots in the Latin word "imperare," meaning "to command."
Rooted in the earliest days of computing, imperative programming forms the basis of traditional programming languages like Pascal, C, and assembly languages. At its core, it revolves around issuing '''explicit commands''' or instructions to direct the computer on how to accomplish a task, reflecting its etymological roots in the Latin word "imperare," meaning "to command."


[[File:Need desk.jpg|frameless|center]]
[[File:Need desk.jpg|800px|frameless|center]]


Within imperative programming, several paradigms emerge, each refining the approach to writing and organizing code:
Within imperative programming, several paradigms emerge, each refining the approach to writing and organizing code:


1. '''Structured Programming''': Introduces control structures like loops and conditionals to enhance code readability and maintainability.
# '''Structured Programming''': Introduces control structures like loops and conditionals to enhance code readability and maintainability.
 
# '''Procedural Programming''': Modularizes code by encapsulating algorithms into functions or procedures, paving the way for better code reuse and abstraction.
2. '''Procedural Programming''': Modularizes code by encapsulating algorithms into functions or procedures, paving the way for better code reuse and abstraction.
# '''Modular Programming''': Extends the procedural paradigm to larger software projects by breaking down code into logical, independent modules for improved clarity and manageability.
 
3. '''Modular Programming''': Extends the procedural paradigm to larger software projects by breaking down code into logical, independent modules for improved clarity and manageability.




Line 24: Line 21:
In contrast to the explicit directives of imperative programming, declarative programming presents a paradigm shift towards expressing '''what''' the program should achieve rather than how to achieve it. This approach, emerging as a response to evolving hardware (back in the days), emphasizes succinctness and abstraction, often resulting in code that is more concise but potentially harder to grasp.
In contrast to the explicit directives of imperative programming, declarative programming presents a paradigm shift towards expressing '''what''' the program should achieve rather than how to achieve it. This approach, emerging as a response to evolving hardware (back in the days), emphasizes succinctness and abstraction, often resulting in code that is more concise but potentially harder to grasp.


'''Instead of telling the programm what to do, step by step (imperative), the program is asked a question (declarative). The parade example here would be a SQL query, that asks, "are there any user with the name X?".'''
Instead of telling the programm what to do, step by step (imperative), the program is '''asked a question''' (declarative). The parade example here would be a SQL query, that asks, "are there any users with the name X?".


[[File:Human comp evol.jpg|frameless|left]]
[[File:Human comp evol.jpg|center|none]]


The two primary methodologies within declarative programming are:
The two primary methodologies within declarative programming are:


1. '''Functional Programming''': Centers around the evaluation of mathematical functions and emphasizes immutability and higher-order functions. Programs are composed of function calls and transformations, facilitating elegant solutions to complex problems.
# '''Functional Programming''': Centers around the evaluation of mathematical functions and emphasizes immutability and higher-order functions. Programs are composed of function calls and transformations, facilitating elegant solutions to complex problems.
 
# '''Logic Programming''': Grounded in mathematical logic, logic programming represents programs as collections of facts and rules. Instead of specifying step-by-step procedures, developers define relationships and constraints, allowing the interpreter to derive solutions from logical deductions.
2. '''Logic Programming''': Grounded in mathematical logic, logic programming represents programs as collections of facts and rules. Instead of specifying step-by-step procedures, developers define relationships and constraints, allowing the interpreter to derive solutions from logical deductions.


 
While imperative programming adheres to the tradition of instructing computers through explicit commands, declarative programming embraces a more abstract and concise approach, defining the desired outcome without prescribing the exact steps to achieve it. Both paradigms offer distinct advantages and have contributed significantly to the diverse landscape of software development.
In summary, while imperative programming adheres to the tradition of instructing computers through explicit commands, declarative programming embraces a more abstract and concise approach, defining the desired outcome without prescribing the exact steps to achieve it. Both paradigms offer distinct advantages and have contributed significantly to the diverse landscape of software development.

Latest revision as of 10:31, 19 January 2025

Implicit and Declarative

Programming paradigms serve as guiding principles, delineating different styles of constructing software code. Among these paradigms, two stand out as foundational: imperative programming and declarative programming.

Imperative Programming

"The Classic Paradigm": Rooted in the earliest days of computing, imperative programming forms the basis of traditional programming languages like Pascal, C and assembly languages. At its core, it revolves around issuing explicit commands or instructions to direct the computer on how to accomplish a task, reflecting its etymological roots in the Latin word "imperare," meaning "to command."

Error creating thumbnail: Unable to save thumbnail to destination

Within imperative programming, several paradigms emerge, each refining the approach to writing and organizing code:

  1. Structured Programming: Introduces control structures like loops and conditionals to enhance code readability and maintainability.
  2. Procedural Programming: Modularizes code by encapsulating algorithms into functions or procedures, paving the way for better code reuse and abstraction.
  3. Modular Programming: Extends the procedural paradigm to larger software projects by breaking down code into logical, independent modules for improved clarity and manageability.



Declarative Programming

Paradigm of the Recent Past In contrast to the explicit directives of imperative programming, declarative programming presents a paradigm shift towards expressing what the program should achieve rather than how to achieve it. This approach, emerging as a response to evolving hardware (back in the days), emphasizes succinctness and abstraction, often resulting in code that is more concise but potentially harder to grasp.

Instead of telling the programm what to do, step by step (imperative), the program is asked a question (declarative). The parade example here would be a SQL query, that asks, "are there any users with the name X?".

Error creating thumbnail: Unable to save thumbnail to destination

The two primary methodologies within declarative programming are:

  1. Functional Programming: Centers around the evaluation of mathematical functions and emphasizes immutability and higher-order functions. Programs are composed of function calls and transformations, facilitating elegant solutions to complex problems.
  2. Logic Programming: Grounded in mathematical logic, logic programming represents programs as collections of facts and rules. Instead of specifying step-by-step procedures, developers define relationships and constraints, allowing the interpreter to derive solutions from logical deductions.

While imperative programming adheres to the tradition of instructing computers through explicit commands, declarative programming embraces a more abstract and concise approach, defining the desired outcome without prescribing the exact steps to achieve it. Both paradigms offer distinct advantages and have contributed significantly to the diverse landscape of software development.