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­ment­al pro­gram­ming paradigms: im­per­at­ive pro­gram­ming or de­clar­at­ive pro­gram­ming. Both of these ap­proaches have their ad­vant­ages and dis­ad­vant­ages.

What are the char­ac­ter­ist­ics of im­per­at­ive pro­gram­ming languages? What weak­nesses do de­velopers need to consider? In this article, we answer the most common questions about the im­per­at­ive paradigm.

What is im­per­at­ive pro­gram­ming?

Im­per­at­ive 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­at­ive 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­teg­rated into the code.

Im­per­at­ive 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­at­ive pro­gram­ming languages.

These are the best-known im­per­at­ive pro­gram­ming languages:

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

The different im­per­at­ive pro­gram­ming languages can, in turn, be assigned to three further sub­or­din­ate pro­gram­ming styles – struc­tured, pro­ced­ur­al, and modular.

The struc­tured pro­gram­ming style extends the basic im­per­at­ive principle with specific control struc­tures: sequences, selection, and iteration. This approach is based on a desire to limit or com­pletely avoid jump state­ments that make im­per­at­ively designed code un­ne­ces­sar­ily com­plic­ated.

The pro­ced­ur­al approach divides the task a program is supposed to perform into smaller sub-tasks, which are in­di­vidu­ally 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­vidu­al program com­pon­ents in­de­pend­ently of one another. The in­di­vidu­al modules are then combined to create the actual software.

De­clar­at­ive vs. im­per­at­ive pro­gram­ming

Im­per­at­ive pro­gram­ming languages differ from de­clar­at­ive languages on one fun­da­ment­al point: im­per­at­ive pro­gram­ming focuses on the “how”, de­clar­at­ive pro­gram­ming on the “what”.

But what does that mean? Im­per­at­ive pro­gram­ming languages are composed of step-by-step in­struc­tions (how) for the computer. They describe ex­pli­citly which steps are to be performed in what order to obtain the desired solution at the end. By contrast, in de­clar­at­ive 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­at­ive languages provide recipes; de­clar­at­ive languages con­trib­ute photos of the finished meal.

In de­clar­at­ive languages, the source code remains very abstract in terms of the specific procedure. To get to the solution, an algorithm is used which auto­mat­ic­ally iden­ti­fies and applies ap­pro­pri­ate methods. This approach has numerous ad­vant­ages: Programs can be written much more quickly, and ap­plic­a­tions are also very easy to optimise. If a new method is developed in the future, the abstract in­struc­tions in the source code mean that the algorithm can easily utilise the newer method.

Im­per­at­ive pro­gram­ming example

Im­per­at­ive pro­gram­ming languages are char­ac­ter­ised by their in­struct­ive nature and, thus, require sig­ni­fic­antly more lines of code to express what can be described with just a few in­struc­tions in the de­clar­at­ive style. In the following example, the aim is to output a list of first names:

Im­per­at­ive pro­gram­ming (PHP)

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

De­clar­at­ive pro­gram­ming (PHP)

$firstnames = array_values($participantlist);

Ad­vant­ages and dis­ad­vant­ages of im­per­at­ive pro­gram­ming languages

Many pro­gram­ming languages based on the im­per­at­ive 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­tern­at­ive models, the im­per­at­ive paradigm still has some practical ad­vant­ages.

The languages are re­l­at­ively 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­at­ive language first as part of their training.

Easy legib­il­ity is a crucial factor in day-to-day op­er­a­tions. Ul­ti­mately, main­ten­ance and op­tim­isa­tion of ap­plic­a­tions should not be linked to a specific person; different employees should be able to do it without too much dif­fi­culty even if they haven’t written the code from scratch them­selves.

One dis­ad­vant­age of pro­ced­ur­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­eated from the pro­gram­ming as it is in the de­clar­at­ive style, therefore, sub­sequent in­ter­ven­tions can produce unwanted errors. Ex­ten­sions are also more difficult to implement in pure im­per­at­ive code – unlike in the de­clar­at­ive paradigm, where there are methods that can be used to add them sep­ar­ately.

Ad­vant­ages Dis­ad­vant­ages
Easy to read Code quickly becomes very extensive and thus confusing
Re­l­at­ively 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­ten­ance blocks ap­plic­a­tion de­vel­op­ment
Char­ac­ter­ist­ics of specific ap­plic­a­tions can be taken into account Op­tim­isa­tion and extension is more difficult

In practice, mixed forms of the paradigms are generally used these days because both, im­per­at­ive and de­clar­at­ive pro­gram­ming styles, have their ad­vant­ages and dis­ad­vant­ages. However, the de­clar­at­ive pro­gram­ming style is becoming in­creas­ingly dominant, sup­ple­men­ted by im­per­at­ive methods.

Go to Main Menu