Programming paradigm
A programming paradigm is a fundamental programming style. "Programming is based on various principles, depending on the design of the individual programming language. These are intended to assist the developer in creating 'good code', in some cases even forcing a particular 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.
Fundamental for the design of programming languages are the paradigms of imperative and declarative programming. In the latter case, the paradigms of functional programming and logical programming are to be mentioned as important characteristics.
The different paradigms, in terms of individual computer programs, are not to be understood as complementary or alternative programming styles. Rather, "many programming languages can support several paradigms simultaneously".
Example
In an application developed under MS Access and with VBA, the functional components are created in an event- and object-oriented way (Ex: "when opening form X"). The VBA code is structured/modular/procedural (because it consists of modules, macros, procedures, etc.); and it is imperative at the same time, because it contains "commands" that are executed (within the procedures...) exactly in the coded sequence. Forms and reports, as well as the SQL calls, are declarative because here the developer specifies only the WHAT and not the HOW.
Nevertheless, programming languages are often called - according to their basic characteristics - e.g. object-oriented, procedural or declarative language. The characteristics determining a paradigm are based predominantly on the properties of the programming languages used (as e.g. with OOP, declarative ...), but partly also on the individual style practiced in programming (e.g. structured, modular).
Often, the "first class citizens" ("FCCs") of a programming language - that is, 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, strings, arrays, and hashes are FCCs.
In addition to programming paradigms, there are a number of other criteria for developing software that is as bug-free and maintainable as possible - such as readability of the program code, freedom from redundancy, modularity, and freedom from side effects. These should be adhered to as much as possible under each paradigm. See also Programming Style.
Imperative programming
→ Main article: Imperative programming
In imperative programming "a program (note: i.e. here the source code) consists of a sequence of commands that specify in which order what should be done by the computer". The term is based on the Latin "imperare" ("to order", "to command").
"Most [...] programming languages, including OOP languages such as C#, Visual Basic, C++, and Java, primarily [also] support imperative [...] programming."
Structured programming
→ Main article: Structured programming
A further development of imperative languages was marked by Edsger W. Dijkstra's 1968 paper Go To Statement Considered Harmful, which called for the abandonment or at least the restriction of absolute jump statements (goto); instead, control structures such as "if... then...", "case... of...", "while... do...", "repeat... until..." should be used.
Procedural programming
→ Main article: Procedural programming
The approach of splitting programs into smaller subtasks is called procedural programming. The resulting subprograms are called procedures. Practically all current imperative programming languages include the procedural approach.
The development of procedural programming languages and techniques were an essential step between assembly language and high-level languages by allowing abstraction and decomposition of algorithms.
Modular programming
→ Main article: Modular programming
Modular programming was the first attempt to cope with the growing size of software projects. In modular programming, the procedural approach is extended by grouping procedures together with data in logical units. The software is thus broken down into larger functional sub-blocks that can be planned, programmed and tested individually. The resulting subprograms are called modules. At the end, the individual parts can then be logically linked together and the software is ready for use. 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
→ Main article: Abstract data type
Programming with abstract data types treats data and functions to handle that data as a unit.
Declarative programming paradigms
→ Main article: Declarative programming
The idea of declarative programming is the historically more recent approach. In contrast to imperative programming paradigms, which focus on the how, declarative programming asks what is to be computed. Thus, instead of programming the solution path, one only specifies what result is desired. For this purpose, declarative paradigms are based on mathematical, computer-independent theories.
- Due to the referential transparency there are no side effects. Programs are thus partially evaluable and thus enable, for example, the handling of infinite data structures.
- Proofs (e.g. proof of correctness, proofs about program properties) are unrestrictedly feasible thanks to mathematical basis (among others lambda calculus).
- Architecture independence
- partly low acceptance (one likes to speak of so-called academic languages)
Declarative programming languages include:
- functional languages (among others Lisp, ML, Miranda, Gofer, Haskell, F#, Scala)
- logicallanguages (including Prolog)
- functional-logical languages (among others Babel, Escher, Curry, Oz)
- quantity-oriented query languages (including SQL)
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, but the computation process is not of interest. The calculations are then done by value manipulation. The main control structure is the recursion, especially for efficiency reasons the final recursion:
Functional programming
→ Main article: Functional programming
The task and the known premises are formulated here as a functional expression. The independent application of function substitution and evaluation on the part of the interpreter or compiler then solve the task. The program can be understood as a mapping of the input to the output.
Logical programming
→ Main article: Logical programming
The task and its premises are formulated as logical statements (rules) (cf. functional programming, see above). The interpreter then tries to derive the desired solution statement. In other rule-based languages such as OPS-5, XSLT, or Prolog, rules are checked against a data set for instantiability. From all rule instantiations, one (several, all) is selected and the statements belonging to the rule are executed.
Constraint programming
→ Main article: Constraint programming
In constraint programming, constraints are defined. It is seen as a natural development of logical programming. Logical and constraint programming are typically used in combination.
Questions and Answers
Q: What is a programming paradigm?
A: A programming paradigm is a way of grouping programming languages based on how they operate.
Q: What are the two main groups of paradigms?
A: The two main groups of paradigms are imperative and declarative.
Q: How do imperative and declarative paradigms differ?
A: Imperative paradigms look at the way that code is run, such as allowing side effects or having to do things in a certain order, while declarative paradigms look at the way that code is grouped, such as putting code into one or two pieces (or instead, many small pieces).
Q: Can a language be both an imperative and declarative paradigm?
A: Yes, a language can be both an imperative and declarative paradigm at the same time.
Q: How does a programming paradigm group languages?
A: Programming paradigms group languages by what they do. They look at how the code is run, how it's grouped, and what order and pieces make up the program.
Q: Are there other types of programming paradigms besides imperative and declarative?
A: Yes, there are other types of programming paradigms besides imperative and declarative. For example, some look at the way that code is run (such as allowing side effects), while others look at the way that code is grouped (such as putting code into one or two pieces).
Q: Does every language belong to only one type of programming paradigm?
A: No, not every language belongs to only one type of programming paradigm; some languages can be in more than one type of paradigm.