0% found this document useful (0 votes)
16 views8 pages

Assignment Final

This document is an assignment on the Declarative Programming Paradigm submitted by a group of students at Addis Ababa University. It covers the definition, history, characteristics, advantages, disadvantages, and main types of declarative programming, including functional and logic programming, as well as database query languages. The document also includes code examples, comparisons with imperative programming, and real-world case studies.

Uploaded by

hailetsion03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Assignment Final

This document is an assignment on the Declarative Programming Paradigm submitted by a group of students at Addis Ababa University. It covers the definition, history, characteristics, advantages, disadvantages, and main types of declarative programming, including functional and logic programming, as well as database query languages. The document also includes code examples, comparisons with imperative programming, and real-world case studies.

Uploaded by

hailetsion03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Addis Ababa University

School of Information Science

Computer Programming I

Title: Assignment on Declarative Programming Paradigm

Group Members:

1. Kaleab Belayhun UGR/7539/17


2. Moa Sisay UGR/5706/17
3. Fraol Masresha UGR/1952/17
4. Girmaye Bulto UGR/0185/17
5. Hayletsion Yibash UGR/8486/17
6. Israel Tsegaye UGR/4738/17
7. Leul Mesfin UGR/9714/17
8. Mahlet Tegete UGR/6422/17
9. Miftah Mohammed UGR/2405/17
10. Saifegebireal Beyene UGR/3494/16

Submitted to: Bantamlak Dejene


Submission Date: 4/10/2025 GC
Table of contents:

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 a programming paradigm—a style of building the


structure and elements of computer programs—that expresses the logic of a
computation without describing its control flow.

The Declarative Programming Paradigm emphasizes what needs to be done, focusing


on the outcome rather than the step-by-step process.

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.

History of declarative programming


Declarative programming has deep roots that trace back to the mid-20th century,
during the early days of computer science. It emphasizes what a program should
accomplish rather than how to accomplish it, distinguishing it from imperative
programming.

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.

Declarative programming also played a significant role in the field of Artificial


Intelligence (AI), particularly in expert systems and knowledge representation
languages. These systems modeled complex reasoning and decision-making processes
through declarative constructs.

In modern software development, declarative programming continues to be influential


across several domains:
● Web Development: Frameworks like React and Vue.js promote declarative UI
construction.
● Data Processing: Technologies such as SQL and LINQ enable high-level data
manipulation.
● Infrastructure as Code: Tools like Terraform and Ansible rely on declarative
configurations to manage infrastructure.
● Functional Programming: Languages like Haskell and F# fully embrace
declarative principles.

Characteristics of Declarative Programming


Declarative programming carries distinct characteristics that differentiate it from other
programming paradigms:

● High-level abstraction: It uses high-level language constructs to write logic


without getting into detailed implementation.
● Focus on results: The programmer specifies the desired output rather than the
operations needed to achieve it.
● Idempotency: Repeated application of declarative logic will yield consistent
results.

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.

Disadvantages of Declarative Programming

● Performance: Sometimes slower, since the control is abstracted.


● Debugging: Harder to debug due to abstraction layers.
● Less control: Not ideal when you need low-level performance or fine-grained
control.
Main Types of Declarative Programming

1. Functional Programming

Functional programming is a prominent type of declarative programming where


computation is treated as the evaluation of mathematical functions. It avoids changing
state and mutable data, promoting a clean and predictable coding style.

Key Features:

● Pure functions (no side effects)


● First-class and higher-order functions
● Immutability
● Strong emphasis on recursion instead of loops
● Lazy evaluation (in languages like Haskell)

Common Functional Languages:

● Haskell – Purely functional and statically typed


● Lisp / Scheme / Clojure – Functional dialects in the Lisp family
● Elixir / F# / Elm – Modern functional-first languages

Use Cases:

● Data analysis, financial modeling, parallel and concurrent systems

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:

● Prolog (Programming in Logic) – The most well-known logic programming


language
● Datalog – A subset used in database querying

Use Cases:

● Artificial intelligence (AI), natural language processing (NLP), expert systems

3. Database Query Languages

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:

● SQL (Structured Query Language)


● XQuery – Used for XML data
● GraphQL – A declarative API query language for retrieving nested data

Use Cases:

● Web applications, business intelligence, reporting systems

5. Markup and Styling Languages

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:

● HTML (HyperText Markup Language) – Structure of web pages


● CSS (Cascading Style Sheets) – Visual appearance

Use Cases:

● Web front-end design, user interface layout, mobile-responsive design

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 = [];

for ($i = 0; $i < count($users); $i++) {


$user = $users[$i];

if ($user->email !== null) {


$emails[] = $user->email;
}
}

return $emails;
}

Declarative Programming Example:

SELECT email FROM users WHERE email IS NOT NULL;

Declarative vs Imperative (JavaScript Example)

Declarative:

var numbers = [1, 2, 3, 4, 5];


var doubled = numbers.map(function(n) {
return n * 2;
});
console.log(doubled); // [2, 4, 6, 8, 10]

Imperative:

var numbers = [1, 2, 3, 4, 5];


var doubled = [];

for (var i = 0; i < numbers.length; i++) {


var newNumber = numbers[i] * 2;
doubled.push(newNumber);
}
console.log(doubled); // [2, 4, 6, 8, 10]

Real world examples

Case Study 1 (Declarative) :

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).

Case Study 2 (Imperative):

Begin – Preparing Coffee

1. Buy the coffee


2. Wash thoroughly
3. Roast
4. Grind
5. Mix with mildly heated water
6. Coffee is ready!

End – Coffee is ready!

Lots of examples and demonstrations will be shown in the presentation!

References
GeeksforGeeks: Declarative Programming Paradigm
freeCodeCamp: Declarative vs Imperative Programming
TutorialsPoint: Logic Programming - Introduction
Stack Overflow: What is Declarative Programming?

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy