Log in Sign up
Back to Discover
💻

Declarative programming

technology Maturity 7-9

Computers use special sets of rules. You tell the computer what you want. You do not tell it every step. This helps the computer work well. It makes writing code easier for us. Can you think of a goal?

39 words

Computers use special rules to work. Some rules tell the computer what to do. These rules do not list every step. Instead, you just say what you want.

This is like telling a friend to make a snack. You do not say every tiny movement. You just ask for the snack. The computer figures out the rest.

Some tools use these rules. One tool helps show things on a web page. It says what should appear. It does not say how to draw it.

Other tools use math to solve problems. They use facts and rules to find answers. This can make hard jobs easier for the computer.

It is a smart way to talk to machines.

119 words

Computers follow rules to finish tasks. Most rules use a set of steps. This is called imperative programming. It tells the computer exactly how to work. Declarative programming is different. It focuses on what the result should be. It does not list every tiny step. You just describe what you want to happen.

One type is logic programming. These programs use facts and rules. The computer uses these to solve problems. A tool called Prolog is a good example. It can find answers by looking at rules. Another tool is Datalog. It works by finding new facts from old ones.

Some tools are for special jobs. These are called domain-specific languages. HTML is one. It tells a web page what to show. It does not say how to draw it. There is also functional programming. This uses math to find answers. Languages like Haskell use this way. This style can make it easier to run many tasks at once. It helps the computer handle hard work in a smart way.

170 words

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.

377 words

Declarative programming is a major paradigm in computer science. It focuses on expressing the logic of a computation. It does not describe the control flow of the program. In this style, a programmer describes what a computation should accomplish. They do not list the specific steps to get there. This is the opposite of imperative programming. Imperative programming uses explicit steps to implement algorithms. Declarative programming often views programs as theories of formal logic. In this view, computations are seen as deductions within a logical space. This approach can greatly simplify the process of writing parallel programs.

To understand the mechanism, compare it to how we solve problems. In an imperative system, you provide a sequence of commands. In a declarative system, you describe the desired result. Many definitions of this style overlap. Some define it as any programming style that is not imperative. Others focus on the lack of side effects. A side effect is a change that happens outside the immediate task. A language with referential transparency is often considered declarative. This means a program has a clear correspondence to mathematical logic. The computer handles the "how" through its own implementation.

Declarative programming is an umbrella term for several sub-paradigms. One major type is logic programming. In logic programming, programs consist of sentences in logical form. Computation involves using these sentences to solve problems. Another type is functional programming. Languages like Haskell use functional programming to evaluate expressions. They use function application to transform data. Functional programming places very little emphasis on explicit sequencing. Instead, it uses recursive higher-order function application. This can be seen as a set of mappings between different domains.

Constraint programming is another important sub-paradigm. It states relations between variables using constraints. These constraints specify the properties of a target solution. The system solves the set by assigning values to each variable. The goal is to stay consistent with the maximum number of constraints. This method often complements functional or logic programming. There are also domain-specific languages, or DSLs. These are languages built for specific tasks. Examples include HTML for web pages or SQL for databases. HTML describes what should appear on a page. It does not describe the control flow for rendering it.

History shows the development of these powerful tools. Prolog, which stands for "PROgramming in LOGic," was developed in 1972. It was created to help computers answer questions using natural language. It uses SL resolution to deduce answers and parse sentences. Datalog is a subset of Prolog that became a separate area around 1977. It lacks compound terms and is not Turing-complete. Most Datalog systems use forward reasoning to derive new facts. Answer set programming, or ASP, evolved in the late 1990s. It is based on the stable model semantics of logic programming. ASP helps solve difficult search problems and knowledge representation.

Specific examples show how these languages function in the real world. The language ML, standing for Meta Language, was introduced in 1973. It is statically typed, meaning types are checked strictly. It is tailored to process lists, much like the Lisp language. In Prolog, the building blocks are facts and rules. For example, a rule might state that every cat is an animal. If you query the system about a specific cat, it uses backward reasoning. It reduces goals to subgoals until it finds a match in the facts. This makes Prolog both a declarative and a procedural language.

Declarative methods also extend to mathematical modeling. Engineers use declarative code to create models of physical systems. These models contain equations rather than imperative assignments. The code declares the behavioral relationships of the system. This allows a computer to perform algebraic manipulations to find solutions. This is used in environments like Modelica or Analytica. By using these systems, programmers can focus on the physics of a problem. They leave the complex math and execution steps to the computer.

648 words
Up Next
💻
Functional programming
Technology
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.