Nepedia
Back to Discover
Fluent Reader
💻

Declarative programming

technology Maturity 7-9 Next article →

Computers use different ways to follow instructions. Most people know about imperative programming. This style gives the computer a long list of steps to follow. It is like a recipe that tells you every single movement. Declarative programming is a different way to work. It focuses on the end result instead of the steps. You describe what you want the computer to do. You do not tell it exactly how to do it.

This way of working uses logic to find answers. In logic programming, you give the computer facts and rules. The computer then uses those to solve a problem. For example, you might tell it that a cat is an animal. If you ask about the cat, it knows it is an animal. It uses these rules to reach a conclusion. This is like solving a puzzle by looking at the pieces. The computer does the heavy lifting to find the right fit.

Many different kinds of tools use this style. Some are called domain-specific languages. These are built for one special job. HTML is a great example of this. It tells a web browser what to show on a page. It does not explain how to draw the pixels. Another type is functional programming. This uses math to get things done. Languages like Haskell use this method to transform data.

History shows us many important tools in this field. Prolog is a famous logic language from 1972. It was made to help computers answer questions using natural language. Datalog is another one that became a separate area around 1977. It is a smaller version of Prolog. It works by finding new facts from old ones. Answer set programming grew in the late 1990s. It helps computers solve very hard search problems.

You can see this style in things you use every day. When you search a database, you might use SQL. SQL is a language used to ask for specific information. You do not tell the database how to search the files. You just tell it what data you want to see. This makes writing programs much simpler for some tasks. It can even help computers do many things at once. This is very helpful for big, hard jobs.

373 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.