What is Imperative Programming?

Imperative programming is a coding style that focuses on describing how a program operates. It involves a sequence of commands that change a program's state, step by step, like a recipe. This approach is foundational in many programming languages, offering a clear structure for developers to follow. How does this method compare to other programming paradigms? Join the conversation to find out.
Victoria Blackburn
Victoria Blackburn

Imperative programming is a method used by computer programmers. The statements that are used in this type of programming give commands to the computer for actions that are to be followed. This is the opposite of declarative programming, which is used to tell the computer what needs to be done without giving details of how the actions are to be taken.

Imperative programming was so named based on imperative mood used in natural languages versus constructed languages, such as computer programming languages. During communication, the imperative tense is used to give a direct command to someone. These commands usually demand a particular action from the audience receiving the message. The command – action result of imperative mood is the same way that this type of programming works with computers.

Scientist with beakers
Scientist with beakers

In some cases, this method of programming is also referred to as procedural programming. Procedural programming refers to the fact that this type of computer programming provides procedures for computers to follow so that a program can be built and run. Procedures are also referred to as subroutines or functions.

From as early as the 1950s, imperative programming has been used. FORTRAN is one of the earliest examples of an imperative programming language. By developing FORTRAN as well as more complex versions of this type of programming, computer programmers were able create much more intricate programs compared to what they were initially able to do using only the machine code of the computer being worked on. This in turn has allowed computers to evolve so they are able to create and run much more advanced applications.

Over time, imperative programming languages have become more and more sophisticated. Variables, expressions, functions and sub-programs are all now a part of a program written using imperative programming. Modern languages include those that follow object-oriented programming. Object-oriented programming uses objects to design and compile computer programs and applications. An object is anything that can be manipulated by running a computer program, which include variables, functions, values and data structures.

Declarative programming is the opposite way of programming from imperative. When computer programmers use declarative programming, they are describing what they want to happen, or the desired results of running their program. Although the results are given, the process to reach those alerts is not. The fact that step-by-step procedures are not provided is the key difference between declarative programming and imperative programming.

You might also Like

Discuss this Article

Post your comments
Forgot password?
    • Scientist with beakers
      Scientist with beakers