Assignment Final
Assignment Final
Computer Programming I
Group Members:
Table of contents:
Introduction: What is declarative programming?
History of declarative programming
Characteristics of Declarative Programming
Advantages of Declarative Programming
Disadvantages of Declarative Programming
Main Types of Declarative Programming
1. Functional Programming
2. Logic Programming
3. Database Query Languages
5. Markup and Styling Languages
Context Independence
Code Examples
Declarative vs Imperative (JavaScript Example)
Real world examples
Case Study 1 (Declarative) :
Case Study 2 (Imperative):
References
Introduction: What is declarative programming?
Declarative programming is all about hiding away complexity and bringing programming
languages closer to human language and thinking. It's the direct opposite of imperative
programming in the sense that the programmer doesn't give instructions about how the
computer should execute the task, but rather on what result is needed.
In the 1960s and 70s, logic programming emerged with languages like Prolog, enabling
developers to express problems through logical statements instead of step-by-step
procedures. Around the same time, functional programming began gaining traction,
particularly in the 1970s and 80s, with languages such as Lisp and Haskell. These
languages championed the use of functions as core building blocks, reinforcing the
declarative paradigm.
Another major milestone came with the development of SQL in the 1970s and its
standardization in the 1980s. SQL revolutionized database querying by allowing users
to specify what data they wanted to retrieve, leaving the method of retrieval to the
system itself.
Free from side effects: Declarative programming opts to avoid side effects, enhancing
predictability and debugging.
Advantages of Declarative Programming
● Improved Readability: Code is generally easier to read and understand since it
focuses on the 'what' rather than the 'how’
● Enhanced Maintainability: Because declarative code is more concise, it's easier
to maintain and less prone to bugs.
● Increased Productivity: Development becomes faster as less code is written,
allowing you to focus on solving more complex problems.
● Parallelism: Declarative programming can naturally express parallelism,
optimizing performance.
1. Functional Programming
Key Features:
Use Cases:
2. Logic Programming
Logic programming is based on formal logic. A program consists of a set of facts and
rules, and computation is done by making logical inferences. Instead of giving step-by-
step instructions, the programmer states facts and rules, and the system derives
answers to queries.
Popular Languages:
Use Cases:
Database query languages are declarative because users specify what data they want,
not the detailed steps to retrieve it. The database management system (DBMS) handles
the execution plan internally.
Popular Languages:
Use Cases:
Markup languages like HTML and styling languages like CSS are declarative because
they describe what content should look like, not how to render it procedurally.
Languages:
Use Cases:
Context Independence
Since declarative programs only declare the ultimate goal (the what), but not the steps
required to reach that goal (the how), they are said to be context independent. What it
means is that regardless of where they are used , the same expressions have the same
meaning in different contexts.
Code Examples
Imperative Programming Example:
function getUserEmails($users) {
$emails = [];
return $emails;
}
Declarative:
Imperative:
Begin – To Go Mexico
Imagine you decided to go to Mexico from 6 Kilo. You didn’t say the route to the driver,
but you just told him to take you. You didn’t tell him the way to Mexico; already, he knew
it (well-defined).
References
GeeksforGeeks: Declarative Programming Paradigm
freeCodeCamp: Declarative vs Imperative Programming
TutorialsPoint: Logic Programming - Introduction
Stack Overflow: What is Declarative Programming?