Imperative programming is a way of writing code in which you write your program as a series of precise instructions or commands for the computer to follow. It is like the steps to execute a recipe in cooking: "Pour the eggs. Add the sugar. Mix well."
For example, when you write code that changes the position or rotation properties of a node in Godot, we say that the code is imperative:
position += velocity * delta
rotation = velocity.angle()
This kind of code is the closest in principle to how a computer works, although when using a scripting language, your code looks much more straightforward than the actual instructions the computer follows.
Languages like GDScript and C#, the two scripting languages of Godot, use the imperative way of programming, also called the imperative paradigm, and mix it with the object-oriented paradigm.
Imperative programming is often put in contrast with declarative programming, which focuses on describing what the result of the code should be rather than giving individual instructions.
Imperative coding writes out all the steps; declarative coding describes the result you want. Imperative programming describe how to obtain a result, declarative programming describes what the result should be.See Also
Related terms in the Glossary