Imperative vs Declarative Programming
Imperative code lists the steps to reach an answer, one change at a time. Declarative code says what answer you want and lets the tool pick the steps.
Imperative Programming
Writing code as a list of steps that change values one at a time.
Imperative programming means writing code as a list of steps. Each step changes something. You tell the computer exactly how to reach the answer, one move at a time. Loops, if statements and variables that change are its main tools. Most beginners learn to code this way first.
Declarative Programming
Writing code that says what you want, and lets the tool work out how.
Declarative programming means writing code that says what result you want. It does not list the steps. The language or tool works out the steps for you. SQL is the best-known example: you ask for rows, and the database picks how to find them. HTML and CSS work this way too. It often makes code shorter and easier to read.
In one line
- Imperative Programming
- Writing code as a list of steps that change values one at a time.
- Declarative Programming
- Writing code that says what you want, and lets the tool work out how.