We are independent & ad-supported. We may earn a commission for purchases made through our links.
Advertiser Disclosure
Our website is an independent, advertising-supported platform. We provide our content free of charge to our readers, and to keep it that way, we rely on revenue generated through advertisements and affiliate partnerships. This means that when you click on certain links on our site and make a purchase, we may earn a commission. Learn more.
How We Make Money
We sustain our operations through affiliate commissions and advertising. If you click on an affiliate link and make a purchase, we may receive a commission from the merchant at no additional cost to you. We also display advertisements on our website, which help generate revenue to support our work and keep our content free for readers. Our editorial team operates independently of our advertising and affiliate partnerships to ensure that our content remains unbiased and focused on providing you with the best information and recommendations based on thorough research and honest evaluations. To remain transparent, we’ve provided a list of our current affiliate partners here.

What is Declarative Programming?

By Archana Khambekar
Updated May 16, 2024
Our promise to you
EasyTechJunkie is dedicated to creating trustworthy, high-quality content that always prioritizes transparency, integrity, and inclusivity above all else. Our ensure that our content creation and review process includes rigorous fact-checking, evidence-based, and continual updates to ensure accuracy and reliability.

Our Promise to you

Founded in 2002, our company has been a trusted resource for readers seeking informative and engaging content. Our dedication to quality remains unwavering—and will never change. We follow a strict editorial policy, ensuring that our content is authored by highly qualified professionals and edited by subject matter experts. This guarantees that everything we publish is objective, accurate, and trustworthy.

Over the years, we've refined our approach to cover a wide range of topics, providing readers with reliable and practical advice to enhance their knowledge and skills. That's why millions of readers turn to us each year. Join us in celebrating the joy of learning, guided by standards you can trust.

Editorial Standards

At EasyTechJunkie, we are committed to creating content that you can trust. Our editorial process is designed to ensure that every piece of content we publish is accurate, reliable, and informative.

Our team of experienced writers and editors follows a strict set of guidelines to ensure the highest quality content. We conduct thorough research, fact-check all information, and rely on credible sources to back up our claims. Our content is reviewed by subject-matter experts to ensure accuracy and clarity.

We believe in transparency and maintain editorial independence from our advertisers. Our team does not receive direct compensation from advertisers, allowing us to create unbiased content that prioritizes your interests.

Declarative programming is a way of specifying what a program should do, rather than specifying how to do it. Most computer languages are based on the steps needed to solve a problem, but some languages only indicate the essential characteristics of the problem and leave it to the computer to determine the best way to solve the problem. The former languages are said to support imperative programming whereas the latter support declarative programming.

One can consider the following example from SQL to get all the sales regions where profit exceeds a certain number, say, $700 US Dollars (USD), from the sales data.

Select Region, Profit from Sales where Profit > 700

This statement does not indicate what the SQL system has to do in order to get the data. The SQL system can go through each sales record and determine whether the condition is satisfied, or, it can quickly obtain the top few records from presorted data. The statement only indicates the nature of the desired data.

Prolog is a declarative programming language which indicates the logical relations between entities.

ancestor(M, C) :- mother(M, C)
ancestor(X, Z) :- mother(X, Y), ancestor(Y, Z)

The above program indicates truisms. If M is the mother of C then M is an ancestor of C. If X is the mother of some person Y who is an ancestor of Z, then X is an ancestor of Z. Given this and some mother-child facts, the program can answer questions about the whole maternal family tree.

During program execution, the Prolog system builds up a number of true statements, thus creating a knowledgebase. This knowledgebase is searched efficiently on its own. The creator of the above program does not specify how to search.

HTML and CSS are declarative programming languages. For instance, the HTML example <table border="1">, indicates a thin border. A CSS example is color: blue. This specifies the text color. As can be seen in these examples, HTML and CSS specify what should appear on a web page but not how to do so.

The advantage of declarative programming languages is mainly two-fold. The programs are concise; this makes it easy even for non-programmers to obtain solutions. In the SQL example above, an analyst or business support person can get the desired information. Similarly, laypersons can write acceptable web pages with simple HTML and CSS commands.

The second advantage of the declarative programming model is that repetitive imperative code that indicates how to solve things is provided in the computer system behind the scenes. Such code can be made highly efficient and can incorporate the best ideas from computing. It can take advantage of parallelism.

EasyTechJunkie is dedicated to providing accurate and trustworthy information. We carefully select reputable sources and employ a rigorous fact-checking process to maintain the highest standards. To learn more about our commitment to accuracy, read our editorial process.
Discussion Comments
By nony — On May 14, 2011

@NathanG - There’s a guy I work with who’s really excited about Ruby programming because of its declarative nature. He says it’s more concise than traditional programming languages. I’ve seen some of the code, and it just looks like a different language.

I’m not sure I understand what the hype is about but I do anticipate these types of languages will become more common in introductory computer courses.

By NathanG — On May 12, 2011

Declarative programming requires a shift in the way that you think. Examples of declarative programming language technologies include Windows Presentation Foundation, which is the new technology from Microsoft that is supposed to be the de facto standard for future Windows development.

Windows Presentation Foundation is completely XML-based, which makes it a little like programming in HTML. That can be a bit disorienting at first. However, the philosophy behind it is to separate function and design. A Windows “form” in the WPF model is an XML document that a designer can modify easily and then send back to the developer to update the code. There is no binary form file as there used to be in the other Rapid Application Development tools.

EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.

EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.