7.4 KiB
Paradigm
By programming language's paradigm (from Greek paradeigma, "pattern", "example") we mean the very essential concepts used as a basis for performing computation in that language. Among the most popular ones we'll find for example the imperative, object oriented and functional, but there's a sizable set of other paradigms in the world; a paradigm can be understood as a set of fundamental ideas, principles and mathematical models (e.g. models of computation, data types, forms of expressions etc.) upon which are built more complex constructs of the language -- paradigm forms foundations which are subsequently accompanied by a kind of "programming philosophy" (expressed for examples as "everything is X" where X may be number, object, array, list etc.), a naturally emerging "mindset", a set of recommendations the programmer should follow when using the language. But let it be set straight that paradigm will NOT include other than purely technical, engineering aspects of computation, i.e. artistic or political ideas (such as "eco-friendlieness", "anti-fascism", ...) are indeed not part of programming paradigm. Nevertheless, although of technical nature, aspects of paradigms are subjective, for example the question of drawing borders between them -- just like music genres or human races, paradigms are fuzzy concepts, they have different definitions in different books, come in different flavors and are often combined; sometimes it's unclear how to classify paradigms (if one strictly falls under another etc.) or even if something is or isn't a paradigm at all. In a wider sense the term paradigm may also be used outside of programming languages, for example a paradigm of a physics engine might be "everything's a sphere" etc.
For example the functional paradigm is built on top of lambda calculus (one of many possible mathematical systems that can be used to perform general calculations) which performs calculations by combining pure mathematical functions -- this then shapes the language so that a programmer will mostly be writing mathematical functions in it, AND this also usually comes with the natural "philosophy" of consequently viewing everything as a function, even such things as loops or numbers themselves. In contrast object oriented (OOP) paradigm aims to solve problems by constructing a network of intercommunicating "objects" and so in OOP we tend to perceive everything as objects.
Most common practically used paradigm is the imperative, one based on the plain and simple concept of issuing "commands" to the computer -- even though nowadays it almost always gets combined with some other bullshit paradigm, most infamously object orientation. Prevalence of imperative paradigm is probably due to more than one factor, most important of which is most likely its simplicity (it's possibly the closest to human thinking, easiest to learn, predict etc.), efficiency thanks to being closest to how computers actually work (compilers have very small overhead in translation, less "magic" is required), historically established status (which is related to simplicity; imperative was the first natural approach to programming), compatibility with minimalism (AKA good design) etc. Even the more abstract paradigms are ultimately erected on top of an imperative system, so imperative computation is present in one way or another.
List of notable paradigms follows (keep in mind the subjectivity and fuzziness that affect classification):
- imperative: Programmer issues commands, the computer blindly executes them ("impero" = "to command"). The focus is on the process of computation. This is the most common paradigm.
- procedural: Programmer writes procedures -- smaller subprograms that together solve the whole problem at hand. This is an extremely common paradigm; procedures are also often called functions, but they mustn't be confused with PURE mathematical functions used in functional paradigm. Examples: Pascal, C, Fortran, ...
- stack-based: Computation happens on stack (or multiple stacks), a data structure very convenient for this purpose. These languages often naturally use prefix or postfix notation, it is easy to implement parameter passing and returning values, many computations are elegant. This is a popular paradigm for minimalist languages. Examples: Forth, comun, ...
- event-driven: Programmer defines reactions to certain external events rather than a single run of a program. This is very often used in GUI programming (with events such as "button clicked", "window resized" etd.). Example: Javascript.
- array-based: Operations mostly work on arrays as opposed to working on single values (scalars).
- ...
- declarative: Programmer defines ("declares") what the result should look like, the program finds something that fits the definition. The focus is on the result, not the process to obtain it.
- functional: Programmer describes solution to a problem as composition of pure mathematical functions (which are not to be confused with more loosely defined "functions" present in many languages). Here everything, even branching and loops, are implemented as strictly mathematical functions that have no side effects. Formally this paradigm is based on lambda calculus. Examples: Haskell, Lisp, ...
- logic: Programmer describes solution using formal logic. Example: Prolog.
- ...
- object oriented (OOP): Programmer defines objects (greatly independent, small encapsulated abstract entities) that communicate with each other to solve given problem. Most generally the paradigm is only about "decomposing problems to objects" and so may be implemented as both imperative and declarative, though nowadays OOP is heavily combined with imperative programming and so is often seen as imperative. Examples: Smalltalk, Java, C++, ...
- class-based
- classless
- ...
- agent oriented (AOP): Very similar to OOP, sometimes very vague, many times seen as OOP extension focusing on concurrency, agents are entities having their own goals (as opposed to mere objects as "service providers").
- ...
The list enumerates just the most important paradigms, other possible paradigms and "almost" paradigms may just include anything connected to any largely useful concept, e.g.: recursive, concurrent, structured, data oriented, visual, set-based, table-based, metaprogramming, nondeterministic, value-level, message-based, generic, reflective, constraint programming, genetic, term rewriting, string-based, symbolic etcetc.