Concept programming is a programming paradigm focusing on how concepts, that live in the programmer's mind, translate into representations that are found in the code space. This approach was introduced in 2001 by Christophe de Dinechin with the XL Programming Language.
Concept programming uses pseudo-metrics to evaluate the quality of code. They are called pseudo-metrics because they relate the concept space and the code space, with a clear understanding that the concept space cannot be formalized strictly enough for a real metric to be defined. Concept programming pseudo-metrics include:
- Syntactic noise measures discrepancies between the concept and the syntax used to represent it. For instance, the semi-colon at the end of statements in C can be considered as syntactic noise, because it has no equivalent in the concept space.
- Semantic noise measures discrepancies between the expected meaning or behavior of the concept and its actual meaning or behavior in the code. For instance, the fact that integer data types overflow (when mathematical integers do not) is a form of semantic noise.
- Bandwidth measures how much of the concept space a given code construct can represent. For instance, the overloaded addition operator in C has higher bandwidth than the
Addinstruction in assembly language, because the C operator can represent addition on floating-point numbers and not just integer numbers.
- Signal/noise ratio measures what fraction of the code space is used for representing actual concepts, as opposed to implementation information.
Rule of equivalence, equivalence breakdown
The rule of equivalence is verified when the code behavior matches the original concept. This equivalence may break down in many cases. Integer overflow breaks the equivalence between the mathematical integer concept and the computerized approximation of the concept.
Many ways to break the equivalence have been given specific names, because they are very common:
- A domain error is a condition where code executes outside of the domain of equivalence, which is the domain where the concept and the implementation match. An integer overflow is an example of domain error.
- A concept cast (also concept recast or concept recasting) is a rewrite of a concept as a different concept because the original concept cannot be represented by the tools. In C, using pointers for output arguments because C doesn't support output arguments explicitly is an example of concept cast.
- A priority inversion is a form of syntactic or semantic noise introduced by some language-enforced general rule. It is called a priority inversion because the language takes precedence over the concept. In Smalltalk, everything is an object, and that rule leads to the undesirable consequence that an expression like 2+3*5 doesn't obey the usual order of operations (Smalltalk interprets this as sending the message * to the number resulting from 2+3, which yields result 25 instead of 17).
To write code, concept programming recommends the following steps:
- Identify and define the relevant concepts in the concept space.
- Identify traditional notations for the concepts, or invent usable notations.
- Identify a combination of programming constructs that allows the concepts to be represented comfortably in code - That includes finding a code notation that matches the notation identified in the previous step as closely as possible.
- Write code that preserves, as much as possible, the expected behavior and semantics of the relevant aspects of the original concept.
XL is the only programming language known to date to be explicitly created for concept programming, but concept programming can be done in nearly any language, with varying degrees of success. Lisp and Forth (and their derivatives) are examples of pre-existing languages which lend themselves well to concept programming.
There are projects that exploit similar ideas to create code with higher level of abstraction. Among them are:
- Intentional Programming
- Language-oriented programming
- Literate programming
- Model-driven architecture
- Programming paradigms
- Automatic programming
- Artefaktur (AAL)
- Abstract syntax tree (AST)
- Language syntax tree (LST)
- Semantic resolution tree (RST)
- Interpretation syntax tree (IST)
- Code generation syntax tree (CST)
- Domain-specific programming language
- The XL Programming Language on SourceForge
- A presentation of Concept Programming
- An interview about Concept Programming on The Register