Programming paradigm

from Wikipedia, the free encyclopedia

A programming paradigm is a fundamental style of programming . “ Programming is based on different principles, depending on the design of the individual programming language. These are intended to support the developer in creating 'good code', in some cases even to force a certain approach to solving problems ”.

Programming paradigms differ in their concepts for representing static (such as objects , methods , variables , constants ) and dynamic (such as assignments , control flow , data flow ) program elements.

The paradigms of imperative and declarative programming are fundamental to the design of programming languages. In the latter, the paradigms of functional programming and logical programming are important characteristics .

In relation to individual computer programs , the different paradigms are not to be understood as complementary or alternative programming styles. Rather, “many programming languages ​​can support several paradigms at the same time”.

example
In an application developed under MS Access and with VBA , the functional components are event-oriented and object- oriented (example: “when opening form X”). The VBA code is structured / modular / procedural (because it consists of modules, macros, procedures, etc.); and at the same time it is imperative because it contains “commands” which (within the procedures ...) are executed exactly in the coded sequence. Forms and reports as well as the SQL calls are declarative because the developer only specifies the WHAT and not the HOW.

Nevertheless, programming languages ​​are often - according to their basic characteristics - z. B. referred to as object-oriented, procedural or declarative language. The characteristics that determine a paradigm are mainly based on the properties of the programming languages ​​used (such as OOP , declarative ...), but also partly on the individual style that is practiced during programming (e.g. structured, modular).

Often the “First Class Citizens” (FCCs) of a programming language - the forms of data that can be used directly - can be used to identify which paradigm the language obeys. In Java (object-oriented), for example, objects are FCCs, in Lisp every piece of program is FCC, in Perl they are strings, arrays and hashes.

In addition to the programming paradigms, there are a number of other criteria for developing software that is as error-free and maintainable as possible - such as readability of the program code, freedom from redundancy , modularity and freedom from side effects . These should be followed as much as possible under each paradigm. See also programming style .

Imperative programming

In imperative programming, "a program (note: that is, the source code here ) consists of a sequence of commands that specify the order in which what should be done by the computer". The name is based on the Latin “imperare” (“to arrange”, “to command”).

"Most [...] programming languages, including OOP languages ​​such as C #, Visual Basic, C ++ and Java, primarily [also] support imperative [...] programming."

Structured programming

The legendary article Go To Statement Considered Harmful by Edsger W. Dijkstra from 1968 marked a further development of imperative languages . It calls for the waiver, or at least the restriction of the absolute jump instructions (Goto); instead, control structures such as "if ... then ...", "case ... of ...", "while ... do ...", "repeat ... until ..." should be used. Pascal is the classic structured programming language .

Procedural programming

The approach of splitting programs into smaller subtasks is called procedural programming. The resulting part programs are called procedures . Practically all current imperative programming languages ​​incorporate the procedural approach.

The development of procedural programming languages ​​and techniques was an essential step between assembly language and high-level languages by enabling abstraction and decomposition of algorithms.

Modular programming

Modular programming was the first attempt at dealing with the growing size of software projects . In modular programming, the procedural approach is expanded by grouping procedures together with data in logical units . The software is broken down into larger functional sub-blocks that can be individually planned, programmed and tested . The resulting subroutines are called modules . In the end, the individual parts can then be logically linked to one another and the software is ready for use. The standardized programming describes the attempt to standardize this process. The first strictly modularized programming language was Modula-2 in 1978 .

Programming with abstract data types

Programming with abstract data types treats data and functions for treating this data as a unit.

Declarative programming paradigms

The idea of ​​declarative programming is the historically more recent approach. In contrast to imperative programming paradigms, in which the how is in the foreground, in declarative programming one asks about what is to be calculated. The solution is no longer programmed, but only indicated which result is required. For this purpose, declarative paradigms are based on mathematical, computer-independent theories.

  • Due to the referential transparency, there are no side effects . Programs can thus be partially evaluated and thus enable, for example, the handling of infinite data structures.
  • Proofs (e.g. correctness proof, proofs about program properties ) can be carried out without restriction thanks to a mathematical basis (including lambda calculus ).
  • Architecture independence
  • partly low acceptance (people like to speak of so-called academic languages)

Declarative programming languages ​​include:

Example Quicksort : Haskell is a typical declarative programming language. The programmer describes what the program does with an input, i.e. how to deal with which input, whereby the calculation process is not of interest. The calculations are then carried out by manipulating values. The main control structure is the recursion , especially the final recursion for reasons of efficiency :

 quicksort [] = []
 quicksort (x:xs) = quicksort [n | n<-xs, n<x] ++ [x] ++ quicksort [n | n<-xs, n>=x]

Functional programming

The task and the known premises are formulated here as a functional expression. The independent application of function substitution and evaluation by the interpreter or compiler then solve the task. The program can be understood as mapping the input to the output.

Logical programming

The task and its premises are formulated as logical statements (rules) (see functional programming, see above). The interpreter then tries to derive the desired solution statement. In the case of other rule-based languages ​​such as OPS-5 , XSLT or Prolog , rules are checked against a quantity of data to determine whether they can be instantiated. One (several, all) is selected from all rule instantiations and the instructions belonging to the rule are executed.

Constraint programming

Constraints are defined in constraint programming . It is understood as a natural further development of logical programming. Logical and constraint programming are typically used in combination.

Object-oriented programming paradigms

Classes are instantiable modules and basic elements in object-oriented programming . According to the object-oriented programming paradigm, objects with data and the routines working on them are combined into units. In contrast, the procedural paradigm keeps the data separate from the routines that process the objects. A computer program is implemented as a set of interacting objects .

Object-oriented programming can be easily combined with event- oriented programming , e.g. B. when programming interactive, graphical user interfaces .

Component-oriented programming paradigms

Using the component-based development of software with abstract and generic component models , software components can be created with strictly defined interfaces .

The reusability of software modules can reduce the development effort and the susceptibility to errors and increase information security . The complete and strict data encapsulation also facilitates the portability of data and programs.

Agent-oriented programming

In agent-oriented programming , the focus is on the concept of the autonomous and planning agent who solves problems independently and in cooperation with other agents.

Aspect-oriented programming

In aspect-oriented programming , the object-oriented concept of class is expanded to include an aspect, thus enabling orthogonal programming.

Generative programming

Generative programming is an umbrella term for the programmatic generation of source code (see book: Generative Programming, Krzysztof Czarnecki, W. Eisenecker)

Generic programming

In the generic programming is attempted, the algorithms for multiple data types to make usable.

Subject-oriented programming

The subject-oriented programming is an extension of object-oriented programming. Above all, it is intended to compensate for the weaknesses of object-oriented programming in the development of large applications and the integration of independently developed applications.

Data stream oriented programming

A continuous flow of data is assumed (mostly audio or video data), which is changed and output (often in real time ).

Graph replacement

In graph replacement, the data is modeled in the form of graphs and the calculations are specified by graph replacement rules, the controlled application of which transforms a given work graph piece by piece.

Concatenative programming

Concatenative programming is characterized by the fact that programs are formed by simply chaining (programming) words. These all operate on the same data structure, which is passed on without the need for any further complex syntax. This means that a natural language syntax such as ABC is possible, for which, for example, C (B (A (x))) would have to be written in other languages . Concatenative programming languages are therefore mostly also stack-based languages, such as Forth , Joy , Cat and PostScript , for reasons of implementation . In contrast to this, applicative programming languages ​​are those that apply functions to arguments. Most imperative and functional languages ​​fall into this category.

Multiparadigmatic programming

Multiparadigmatic languages ​​unite different paradigms. Examples are F-Sharp , Lisp , OCaml, and Swift .

Web links

Wiktionary: programming paradigm  - explanations of meanings, word origins, synonyms, translations

Individual evidence

  1. ^ Bjarne Stroustrup: Conference on History of Programming Languages: Evolving a language in and for the real world: C ++ 1991-2006. (PDF) Retrieved September 20, 2010 (English): "C ++ supports several programming styles or, as they are sometimes somewhat pretentiously called," programming paradigms "."
  2. a b Andreas M. Böhm, Bettina Jungkunz: Basic course in IT professions . Vieweg, 2005, ISBN 978-3-528-05913-2 .
  3. a b Functional programming or imperative programming? In: MSDN . Microsoft , accessed April 3, 2013 .
  4. Concatenative language. Concatenative , accessed September 20, 2010 .
  5. ^ Dominikus Herzberg, Tim Reichert: Concatenative Programming. (PDF; 315 kB) 2009, archived from the original on February 27, 2012 ; accessed on September 20, 2010 (English).