Programming paradigms: What are the principles of programming?
Programming paradigms are the fundamental principles used when developing software. They are best described as fundamentally different programming styles, which in turn result in differently structured software code.
The classic concept is imperative programming, where the source code clearly defines which steps a program has to complete and in what order. Sub-types include procedural and object-oriented programming. On the other hand, the declarative programming principle involves describing only what software should do (i.e. only the result and not the individual steps). Sub-types include functional programming and logic programming. How do the two programming paradigms differ from one another?
Imperative programming: The classic programming paradigm
Among programming paradigms for software development, imperative programming is the classic variant. The first programming languages – and correspondingly, the first computer programs – were based entirely on this classic approach, which provides a controlled sequence of specific commands (the name comes from the Latin imperare meaning “command”) or instructions. For example, this programming paradigm is the basis for early classics like Pascal and C, as well as all assembly languages. Imperative programming focuses in part on working as closely as possible with the system. The resulting program code is therefore easy to understand but also very extensive.
Within the imperative programming paradigm, there are three important subordinate methods for writing and structuring software code: structured, procedural, and modular programming.
You can find out more about the imperative programming paradigm in our corresponding article, which takes a more in-depth look at the topic.
Structured programming
The structured programming method is a simplified form of imperative programming. The crucial difference from the basic principle is that instead of absolute jump commands (instructions that lead to processing continuing at another point instead of the next command), this software programming paradigm makes use of control loops and structures. An example is the use of “do...while”, which executes an instruction automatically for as long as a particular condition is true (at least once).
Procedural programming
The procedural programming paradigm extends the imperative approach with the possibility of dividing algorithms into more manageable sections. Depending on the programming language, these are referred to as sub-programs, routines, or functions. The purpose of this division is to make the programming code clearer and to prevent unnecessary code repetitions. Because of the abstraction of algorithms, the procedural software paradigm represents a crucial step from simple assembly languages towards more complex high-level languages.
Modular programming
Modular programming is categorized as a subordinate form of the imperative programming paradigm. It is essentially very similar to the procedural method and applies this programming style to the requirements and demands of larger and more comprehensive software projects. It involves selectively breaking down the source code into logical, independent sub-blocks to ensure greater clarity and to simplify the debugging process. The sub-blocks, known as modules, can be tested individually before they are subsequently linked together to create a collective application.
Declarative programming: paradigm of the recent past
In parallel to the continuous ongoing development of hardware and software, the declarative method developed as an alternative paradigm for code programming. The fundamental principle of declarative programming is that it describes the desired end result. Thus, it is primarily about the “what” – the result – rather than the “how” – the steps towards the solution – as is the case with imperative programming. As a consequence, because of the high level of abstraction, the code generated by declarative programming is much more difficult to understand. At the same time, it is short and precise.
There are much bigger differences between subordinate forms of the declarative programming paradigm than there are between those of the imperative approach. In addition, they are not always so precisely defined or categorized. The two most important methods in the declarative programming paradigm are functional and logic programming.
You can find out more about the declarative programming paradigm in our corresponding article, which takes a more in-depth look at the topic.
Functional programming
Functions exist in every higher-level programming language. However, the functional approach in software development deals with functions in a very particular way.
A functionally programmed program is made up of a string of function calls, where each program section can be understood as a function. In functional programming, the functions can take on different forms. For example, they can be linked to one another like data or be used in the form of parameters. In addition, they can subsequently be used as function results. Conversely, the paradigm leads to there being no independent assignment of values.
This subsidiary form of declarative programming is very important for computer science in general – and at the same time can be used for a wide range of specific purposes. The special handling of functions enables programmers using the functional method to create and use extensive calculation rules made up of functions.
You can find out more about the functional programming method in our corresponding article, which takes a more in-depth look at the topic.
Logic programming
The logic programming method, also known as predicate programming, is based on mathematical logic. Instead of a sequence of instructions, software programmed using this method contains a set of principles, which can be understood as a collection of facts and assumptions. All inquiries to the program are processed, with the interpreter applying these principles and previously defined rules to them in order to obtain the desired result.
You can find out more about the logic programming method in our corresponding article, which takes a more in-depth look at the topic.
Comparison of programming paradigms: imperative and declarative programming
Imperative programming paradigm | Declarative programming paradigm |
---|---|
“How?” | “What?” |
Classic | New trend |
A program based on this paradigm is made up of a series of instructions that tell the computer what it should calculate/do and in what order. | A program based on this paradigm is made up of instructions for how the program should deal with an input. Calculations are performed by manipulation of values, with the procedure controlled by the process of recursion. |
The name comes from “imperare”, the Latin word for “command”. | The name comes from “declarare”, the Latin word for “describe”. |
The desired solution path is specified | The desired result is specified. |
Typical programming languages include C, Pascal, Fortran, ALGOL, and all assembly languages. | Typical programming languages include Lisp, ML, Haskell, F#, Prolog, and Oz |