Whether for app de­vel­op­ment, pro­gram­ming of machines, or the de­vel­op­ment of business software – the developer has to decide which pro­gram­ming language to use before the first line of code is written. There’s a wide range of pro­gram­ming languages available but each of them can be assigned to one of two fun­da­men­tal pro­gram­ming paradigms: im­per­a­tive pro­gram­ming or de­clar­a­tive pro­gram­ming. Both of these ap­proach­es have their ad­van­tages and dis­ad­van­tages.

What are the char­ac­ter­is­tics of im­per­a­tive pro­gram­ming languages? What weak­ness­es do de­vel­op­ers need to consider? In this article, we answer the most common questions about the im­per­a­tive paradigm.

What is im­per­a­tive pro­gram­ming?

Im­per­a­tive pro­gram­ming (from Latin imperare = command) is the oldest pro­gram­ming paradigm. A program based on this paradigm is made up of a clearly-defined sequence of in­struc­tions to a computer.

Therefore, the source code for im­per­a­tive languages is a series of commands, which specify what the computer has to do – and when – in order to achieve a desired result. Values used in variables are changed at program runtime. To control the commands, control struc­tures such as loops or branches are in­te­grat­ed into the code.

Im­per­a­tive pro­gram­ming languages are very specific, and operation is system-oriented. On the one hand, the code is easy to un­der­stand; on the other hand, many lines of source text are required to describe what can be achieved with a fraction of the commands using de­clar­a­tive pro­gram­ming languages.

These are the best-known im­per­a­tive pro­gram­ming languages:

  • Fortran
  • Java
  • Pascal
  • ALGOL
  • C
  • C#
  • C++
  • Assembler
  • BASIC
  • COBOL
  • Python
  • Ruby

The different im­per­a­tive pro­gram­ming languages can, in turn, be assigned to three further sub­or­di­nate pro­gram­ming styles – struc­tured, pro­ce­dur­al, and modular.

The struc­tured pro­gram­ming style extends the basic im­per­a­tive principle with specific control struc­tures: sequences, selection, and iteration. This approach is based on a desire to limit or com­plete­ly avoid jump state­ments that make im­per­a­tive­ly designed code un­nec­es­sar­i­ly com­pli­cat­ed.

The pro­ce­dur­al approach divides the task a program is supposed to perform into smaller sub-tasks, which are in­di­vid­u­al­ly described in the code. This results in pro­gram­ming modules which can also be used in other programs. The modular pro­gram­ming model goes one step further by designing, de­vel­op­ing, and testing the in­di­vid­ual program com­po­nents in­de­pen­dent­ly of one another. The in­di­vid­ual modules are then combined to create the actual software.

De­clar­a­tive vs. im­per­a­tive pro­gram­ming

Im­per­a­tive pro­gram­ming languages differ from de­clar­a­tive languages on one fun­da­men­tal point: im­per­a­tive pro­gram­ming focuses on the “how”, de­clar­a­tive pro­gram­ming on the “what”.

But what does that mean? Im­per­a­tive pro­gram­ming languages are composed of step-by-step in­struc­tions (how) for the computer. They describe ex­plic­it­ly which steps are to be performed in what order to obtain the desired solution at the end. By contrast, in de­clar­a­tive pro­gram­ming, the desired result (what) is described directly. This becomes clearer when using a cooking analogy for il­lus­tra­tion: im­per­a­tive languages provide recipes; de­clar­a­tive languages con­tribute photos of the finished meal.

In de­clar­a­tive languages, the source code remains very abstract in terms of the specific procedure. To get to the solution, an algorithm is used which au­to­mat­i­cal­ly iden­ti­fies and applies ap­pro­pri­ate methods. This approach has numerous ad­van­tages: Programs can be written much more quickly, and ap­pli­ca­tions are also very easy to optimize. If a new method is developed in the future, the abstract in­struc­tions in the source code mean that the algorithm can easily utilize the newer method.

Im­per­a­tive pro­gram­ming example

Im­per­a­tive pro­gram­ming languages are char­ac­ter­ized by their in­struc­tive nature and, thus, require sig­nif­i­cant­ly more lines of code to express what can be described with just a few in­struc­tions in the de­clar­a­tive style. In the following example, the aim is to output a list of first names:

Im­per­a­tive pro­gram­ming (PHP)

$participantlist = [1 => 'Peter', 2 => 'Henry', 3 => 'Sarah'];
$firstnames= [];
foreach ($participantlist as $id => $name) {
    $firstnames[] = $name;
}

De­clar­a­tive pro­gram­ming (PHP)

$firstnames = array_values($participantlist);

Ad­van­tages and dis­ad­van­tages of im­per­a­tive pro­gram­ming languages

Many pro­gram­ming languages based on the im­per­a­tive pro­gram­ming paradigm are in use today.

On the one hand, this is because the approach is the original form of pro­gram­ming. On the other hand, despite the existence of al­ter­na­tive models, the im­per­a­tive paradigm still has some practical ad­van­tages.

The languages are rel­a­tive­ly easy to learn, as the code can be read like a step-by-step in­struc­tion. Therefore, pro­gram­mers normally learn an im­per­a­tive language first as part of their training.

Easy leg­i­bil­i­ty is a crucial factor in day-to-day op­er­a­tions. Ul­ti­mate­ly, main­te­nance and op­ti­miza­tion of ap­pli­ca­tions should not be linked to a specific person; different employees should be able to do it without too much dif­fi­cul­ty even if they haven’t written the code from scratch them­selves.

One dis­ad­van­tage of pro­ce­dur­al pro­gram­ming is that for more complex problems to be solved, the amount of code quickly starts to grow. It remains easy to read but becomes confusing due to its volume.

Execution is not clearly de­lin­eat­ed from the pro­gram­ming as it is in the de­clar­a­tive style, therefore, sub­se­quent in­ter­ven­tions can produce unwanted errors. Ex­ten­sions are also more difficult to implement in pure im­per­a­tive code – unlike in the de­clar­a­tive paradigm, where there are methods that can be used to add them sep­a­rate­ly.

Ad­van­tages Dis­ad­van­tages
Easy to read Code quickly becomes very extensive and thus confusing
Rel­a­tive­ly easy to learn Higher risk of errors when editing
Con­cep­tu­al model (solution path) is very easy for beginners to un­der­stand System-oriented pro­gram­ming means that main­te­nance blocks ap­pli­ca­tion de­vel­op­ment
Char­ac­ter­is­tics of specific ap­pli­ca­tions can be taken into account Op­ti­miza­tion and extension is more difficult

In practice, mixed forms of the paradigms are generally used these days because both, im­per­a­tive and de­clar­a­tive pro­gram­ming styles, have their ad­van­tages and dis­ad­van­tages. However, the de­clar­a­tive pro­gram­ming style is becoming in­creas­ing­ly dominant, sup­ple­ment­ed by im­per­a­tive methods.

Go to Main Menu