Programming paradigm: Difference between revisions
Seizethedave (talk | contribs) m links |
m Reverted edits by 217.96.227.69 (talk) (HG) (3.4.12) |
||
(838 intermediate revisions by more than 100 users not shown) | |||
Line 1: | Line 1: | ||
{{Short description|High-level computer programming conceptualization}} |
|||
{{Expand|date=February 2008}} |
|||
{{About|classification of programming languages|definition of the term "programming model"|Programming model}} |
|||
A '''programming paradigm''' is a fundamental style of [[computer programming]]. (Compare with a [[methodology (software engineering)|methodology]], which is a style of solving specific [[software engineering]] problems). |
|||
A '''programming paradigm''' is a relatively high-level way to conceptualize and structure the implementation of a [[computer program]]. A [[programming language]] can be classified as supporting one or more paradigms.<ref>{{cite web |title=Multi-Paradigm Programming Language |url=https://developer.mozilla.org/en-US/docs/multiparadigmlanguage.html |website=Mozilla Developer Network |date= Jun 21, 2013 |publisher=[[Mozilla Foundation]] |archive-url=https://web.archive.org/web/20130821052407/https://developer.mozilla.org/en-US/docs/multiparadigmlanguage.html |archive-date=21 August 2013}}</ref> |
|||
A [[programming language]] can support [[Multi-paradigm programming language|multiple paradigms]]. For example programs written in [[C++]] or [[Object Pascal]] can be purely [[procedural programming|procedural]], or purely [[object-oriented programming|object-oriented]], or contain elements of both paradigms. Software designers and programmers decide how to use those paradigm elements. |
|||
Paradigms are separated along and described by different dimensions of programming. Some paradigms are about implications of the [[execution model]], such as allowing [[Side effect (computer science)|side effects]], or whether the sequence of operations is defined by the execution model. Other paradigms are about the way code is organized, such as grouping into units that include both state and behavior. Yet others are about [[Syntax (programming languages)|syntax]] and [[Formal grammar|grammar]]. |
|||
In [[object-oriented programming]], programmers can think of a program as a collection of interacting objects, while in [[functional programming]] a program can be thought of as a sequence of stateless function evaluations. When programming computers or systems with many processors, [[process-oriented programming]] allows programmers to think about applications as sets of concurrent processes acting upon logically shared [[data structures]]. |
|||
Some common programming paradigms include (shown in [[hierarchical relationship]]):<ref>Nørmark, Kurt. ''[http://people.cs.aau.dk/~normark/prog3-03/html/notes/paradigms_themes-paradigm-overview-section.html Overview of the four main programming paradigms]''. Aalborg University, 9 May 2011. Retrieved 22 September 2012.</ref><ref>{{cite web |author=Frans Coenen |date=1999-10-11 |title=Characteristics of declarative programming languages |url=http://cgi.csc.liv.ac.uk/~frans/OldLectures/2CS24/declarative.html#detail |url-status=live |access-date=2014-02-20 |website=cgi.csc.liv.ac.uk |language=en-US|archive-date=2014-02-27|archive-url=https://web.archive.org/web/20140227142223/http://cgi.csc.liv.ac.uk/~frans/OldLectures/2CS24/declarative.html}}</ref><ref name="symbolic-programming-lisp">{{cite web |
|||
Just as different groups in [[software engineering]] advocate different ''methodologies'', different [[programming languages]] advocate different ''programming paradigms''. Some languages are designed to support one particular paradigm ([[Smalltalk]] supports object-oriented programming, [[Haskell (programming language)|Haskell]] supports functional programming), while other programming languages support multiple paradigms (such as [[Object Pascal]], [[C++]], [[C Sharp (programming language)|C#]], [[Visual Basic|Visual Basic]], [[Common Lisp]], [[Scheme (programming language)|Scheme]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]] and [[Oz programming language|Oz]]). |
|||
|url = http://www.ai.uga.edu/mc/LispNotes/FirstLectureOnSymbolicProgramming.pdf |
|||
|title = CSCI/ARTI 4540/6540: First Lecture on Symbolic Programming and LISP |
|||
|date = 2010-08-23 |
|||
|access-date = 2013-11-20 |
|||
|author = Michael A. Covington |
|||
|publisher = University of Georgia |
|||
|archive-url = https://web.archive.org/web/20120307124013/http://www.ai.uga.edu/mc/LispNotes/FirstLectureOnSymbolicProgramming.pdf |
|||
|archive-date = 2012-03-07 |
|||
|url-status = dead |
|||
}}</ref> |
|||
* [[imperative programming|Imperative]] {{endash}} code directly controls [[Control flow|execution flow]] and state change, explicit statements that change a program state |
|||
** [[procedural programming|procedural]] {{endash}} organized as [[function (computer programming)|procedures]] that call each other |
|||
** [[object-oriented programming|object-oriented]] {{endash}} organized as [[Object (computer science)|objects]] that contain both data structure and associated behavior, uses data structures consisting of data fields and methods together with their interactions (objects) to design programs |
|||
*** [[Class (computer programming)|Class-based]] – object-oriented programming in which inheritance is achieved by defining classes of objects, versus the objects themselves |
|||
*** [[Prototype-based programming|Prototype-based]] – object-oriented programming that avoids classes and implements inheritance via cloning of instances |
|||
* [[declarative programming|Declarative]] {{endash}} code declares properties of the desired result, but not how to compute it, describes what computation should perform, without specifying detailed state changes |
|||
** [[functional programming|functional]] {{endash}} a desired result is declared as the value of a series of function evaluations, uses evaluation of mathematical functions and avoids state and mutable data |
|||
** [[logic programming|logic]] {{endash}} a desired result is declared as the answer to a question about a system of facts and rules, uses explicit mathematical logic for programming |
|||
** [[Reactive programming|reactive]] {{endash}} a desired result is declared with data streams and the propagation of change |
|||
*[[Concurrent programming language|Concurrent programming]] – has language constructs for concurrency, these may involve multi-threading, support for distributed computing, message passing, shared resources (including shared memory), or [[Futures and promises|futures]] |
|||
**[[Actor model|Actor programming]] – concurrent computation with ''actors'' that make local decisions in response to the environment (capable of selfish or competitive behaviour) |
|||
*[[Constraint programming]] – relations between variables are expressed as constraints (or constraint networks), directing allowable solutions (uses constraint satisfaction or [[simplex algorithm]]) |
|||
*[[Dataflow|Dataflow programming]] – forced recalculation of formulas when data values change (e.g. [[Spreadsheet|spreadsheets]]) |
|||
*[[Distributed computing|Distributed programming]] – has support for multiple autonomous computers that communicate via computer networks |
|||
*[[Generic programming]] – uses algorithms written in terms of to-be-specified-later types that are then instantiated as needed for specific types provided as parameters |
|||
*[[Metaprogramming]] – writing programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime |
|||
**[[Template metaprogramming]] – metaprogramming methods in which a compiler uses templates to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled |
|||
**[[Reflective programming]] – metaprogramming methods in which a program modifies or extends itself |
|||
*[[Pipeline programming]] – a simple syntax change to add syntax to nest function calls to language originally designed with none |
|||
*[[Rule-based programming]] – a network of rules of thumb that comprise a knowledge base and can be used for expert systems and problem deduction & resolution |
|||
*[[Visual programming language|Visual programming]] – manipulating program elements graphically rather than by specifying them textually (e.g. [[Simulink]]); also termed ''diagrammatic programming'' |
|||
== Overview == |
|||
Many programming paradigms are as well known for what techniques they ''forbid'' as for what they enable. For instance, pure functional programming disallows the use of [[Side-effect_(computer_science)|side-effects]]; [[structured programming]] disallows the use of the [[GOTO|goto]] statement. Partly for this reason, new paradigms are often regarded as doctrinaire or overly rigid by those accustomed to earlier styles. {{Fact|date=January 2008}} Avoiding certain techniques can make it easier to prove theorems about a program's correctness—or simply to understand its behavior. |
|||
[[File:Programming paradigms.svg|thumb|250px|left|Overview of the various programming paradigms according to Peter Van Roy<ref>{{Cite web |
|||
|url= http://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf |
|||
|title= Programming Paradigms: What Every Programmer Should Know |
|||
|date= 2009-05-12 |access-date= 2014-01-27 |
|||
|author= Peter Van Roy |publisher= info.ucl.ac.be |
|||
}}</ref>{{rp|5}}<ref name="Van-RoyHaridi2004">{{cite book|author1=Peter Van-Roy|author2=Seif Haridi|title=Concepts, Techniques, and Models of Computer Programming|url=https://books.google.com/books?id=_bmyEnUnfTsC|year=2004|publisher=MIT Press|isbn=978-0-262-22069-9}}</ref>]] |
|||
Programming paradigms come from [[computer science]] [[research]] into existing practices of [[software development]]. The findings allow for describing and comparing programming practices and the languages used to code programs. For perspective, other fields of research study |
|||
== Examples == |
|||
[[software engineering]] [[process]]es and describe various [[Methodology|methodologies]] to describe and compare them. |
|||
{{Prose|date=February 2008}} |
|||
*Annotative programming (as in [http://flarelang.sourceforge.net Flare language]) |
|||
A [[programming language]] can be described in terms of paradigms. Some languages support only one paradigm. For example, [[Smalltalk]] supports object-oriented and [[Haskell]] supports functional. Most languages support multiple paradigms. For example, a program written in [[C++]], [[Object Pascal]], or [[PHP]] can be purely [[Procedural programming|procedural]], purely [[Object-oriented programming|object-oriented]], or can contain aspects of both paradigms, or others. |
|||
*[[Aspect-oriented programming]] (as in [[AspectJ]]) |
|||
*[[Attribute-Oriented Programming]] <!--(might be the same as annotative programming) ... is not-->(as in [[Java annotation | Java 5 Annotations]], pre-processed by the XDoclet class; C# Attributes) |
|||
When using a language that supports multiple paradigms, the developer chooses which paradigm elements to use. But, this choice may not involve considering paradigms per se. The developer often uses the features of a language as the language provides them and to the extent that the developer knows them. Categorizing the resulting [[Source code|code]] by paradigm is often an academic activity done in retrospect. |
|||
*[[Automata-Based Programming]] |
|||
*[[Bayesian programming]] |
|||
Languages categorized as '''imperative paradigm''' have two main features: they state the order in which operations occur, with constructs that explicitly control that order, and they allow side effects, in which state can be modified at one point in time, within one unit of code, and then later read at a different point in time inside a different unit of code. The communication between the units of code is not explicit. |
|||
*[[Class-based programming]], compared to [[Prototype-based programming]] (within the context of object-oriented programming) |
|||
*[[Software componentry|Component-oriented programming]] (as in [[object linking and embedding|OLE]]) |
|||
In contrast, languages in the '''declarative paradigm''' do not state the order in which to execute operations. Instead, they supply a number of available operations in the system, along with the conditions under which each is allowed to execute.<ref>{{Cite web |title=Programming paradigms: What are the principles of programming? |url=https://www.ionos.com/digitalguide/websites/web-development/programming-paradigms/ |url-status=live |access-date=2022-05-03 |website=IONOS Digitalguide |date=20 April 2020 |language=en-US |archive-url=https://web.archive.org/web/20220629200645/https://www.ionos.com/digitalguide/websites/web-development/programming-paradigms/ |archive-date=Jun 29, 2022}}</ref> The implementation of the language's execution model tracks which operations are free to execute and chooses the order independently. More at [[Comparison of multi-paradigm programming languages]]. |
|||
*[[Concatenative programming]] |
|||
*[[Constraint programming]], compared to [[logic programming]] |
|||
In '''object-oriented''' programming, code is organized into [[Object (programming)|objects]] that contain state that is owned by and (usually) controlled by the code of the object. Most object-oriented languages are also imperative languages. |
|||
*[[Context-oriented programming]] (as in [http://www.swa.hpi.uni-potsdam.de/cop/ ContextJ/ContextS/ContextL]) |
|||
*[[Cybernetics Oriented Programming]] |
|||
In object-oriented programming, programs are treated as a set of interacting objects. In [[functional programming]], programs are treated as a sequence of stateless function evaluations. When programming computers or systems with many processors, in [[process-oriented programming]], programs are treated as sets of concurrent processes that act on a logical shared [[data structure]]s. |
|||
*[[Dataflow|Dataflow programming]] (as in [[spreadsheet]]s) |
|||
*[[Declarative programming]] |
|||
Many programming paradigms are as well known for the techniques they ''forbid'' as for those they ''support''. For instance, pure functional programming disallows [[side-effect (computer science)|side-effects]], while [[structured programming]] disallows the [[goto]] construct. Partly for this reason, new paradigms are often regarded as doctrinaire or overly rigid by those accustomed to older ones.<ref name="rubin87goto">{{cite journal|author=Frank Rubin |date=March 1987 |url=http://www.ecn.purdue.edu/ParaMount/papers/rubin87goto.pdf |title='GOTO Considered Harmful' Considered Harmful |journal=Communications of the ACM |volume=30 |issue=3 |pages=195–196 |doi=10.1145/214748.315722 |s2cid=6853038 |url-status = dead|archive-url=https://web.archive.org/web/20090320002214/http://www.ecn.purdue.edu/ParaMount/papers/rubin87goto.pdf |archive-date=March 20, 2009}}</ref> Yet, avoiding certain techniques can make it easier to understand program behavior, and to [[Automated theorem proving|prove theorems]] about program correctness. |
|||
*[[Flow-based programming]] |
|||
*[[Function-level programming]] |
|||
Programming paradigms can also be compared with ''[[programming model]]s'', which allows invoking an [[execution model]] by using only an API. Programming models can also be classified into paradigms based on features of the execution model. |
|||
*[[Functional programming]] |
|||
*Goal-directed programming as in [[Snobol]], somewhat similar to [[Logic Programming]] |
|||
For [[parallel computing]], using a programming model instead of a language is common. The reason is that details of the parallel hardware leak into the abstractions used to program the hardware. This causes the programmer to have to map patterns in the algorithm onto patterns in the execution model (which have been inserted due to leakage of hardware into the abstraction). As a consequence, no one parallel programming language maps well to all computation problems. Thus, it is more convenient to use a base sequential language and insert API calls to parallel execution models via a programming model. Such parallel programming models can be classified according to abstractions that reflect the hardware, such as [[shared memory]], [[distributed memory]] with [[message passing]], notions of ''place'' visible in the code, and so forth. These can be considered flavors of programming paradigm that apply to only parallel languages and programming models. |
|||
*[[Imperative programming]], compared to [[declarative programming]]<!--*[[Intentional Programming]] is a vapor paradigm, it essentially doesn't exist--> |
|||
*[[Intentional programming]] |
|||
== Criticism == |
|||
*[[Literate Programming]] |
|||
*[[Logic programming]] (as in [[Prolog]]) and [[Abductive Logic Programming]] |
|||
Some programming language researchers criticise the notion of paradigms as a classification of programming languages, e.g. Harper,<ref>{{cite web|first=Robert|last=Harper|title=What, if anything, is a programming-paradigm?|url=http://www.cambridgeblog.org/2017/05/what-if-anything-is-a-programming-paradigm/|website = FifteenEightyFour|publisher = Cambridge University Press|date = 1 May 2017}}</ref> and Krishnamurthi.<ref>{{cite journal |first= Shriram |last= Krishnamurthi |publisher= ACM |url= http://dl.acm.org/citation.cfm?id=1480846 |title= Teaching programming languages in a post-linnaean age |journal= ACM SIGPLAN Notices |date= November 2008 |volume= 43 |issue= 11 |pages= 81–83|doi= 10.1145/1480828.1480846 |s2cid= 35714982 }}.</ref> They argue that many programming languages cannot be strictly classified into one paradigm, but rather include features from several paradigms. See [[Comparison of multi-paradigm programming languages]]. |
|||
*[[Message passing programming]], compared to imperative programming |
|||
*[[Nondeterministic programming]] |
|||
== History == |
|||
*[[Object-oriented programming]] (as in [[Smalltalk|Smalltalk]]) |
|||
*[[Pipeline programming]] (as in the [[pipeline (Unix)|UNIX command line]]) |
|||
Different approaches to programming have developed over time. Classification of each approach was either described at the time the approach was first developed, but often not until some time later, retrospectively. An early approach consciously identified as such is [[structured programming]], advocated since the mid 1960s. The concept of a ''programming paradigm'' as such dates at least to 1978, in the [[Turing Award]] lecture of [[Robert W. Floyd]], entitled ''The Paradigms of Programming'', which cites the notion of paradigm as used by [[Thomas Kuhn]] in his ''[[The Structure of Scientific Revolutions]]'' (1962).<ref>{{Cite journal |last1= Floyd |first1= R. W. |title= The paradigms of programming | doi= 10.1145/359138.359140 |journal= Communications of the ACM |volume= 22 |issue= 8 |pages= 455–460 |year= 1979 |doi-access= free }}</ref> Early programming languages did not have clearly defined programming paradigms and sometimes programs made extensive use of goto statements. Liberal use of which lead to [[spaghetti code]] which is difficult to understand and maintain. This led to the development of structured programming paradigms that disallowed the use of goto statements; only allowing the use of more structured programming constructs.<ref>{{cite book | url=https://books.google.com/books?id=POAplMgrk4wC&dq=programming+paradigm+structured&pg=PA20 | title=Java 5: Objects First | isbn=9780763737207 | last1=Soroka | first1=Barry I. | year=2006 | publisher=Jones & Bartlett Learning }}</ref> |
|||
*[[Policy-based design|Policy-based programming]] |
|||
*[[Procedural programming]], compared to [[functional programming]] |
|||
== Languages and paradigms == |
|||
*[[Process-oriented programming]] a parallel programming model. |
|||
*[[Reactive programming]] |
|||
=== Machine code === |
|||
*[[Recursion (computer science)|Recursive programming]], compared to [[iteration|iterative programming]] |
|||
*[[Reflective programming]] |
|||
[[Machine code]] is the lowest-level of computer programming as it is [[Instruction set|machine instructions]] that define behavior at the lowest level of abstract possible for a computer. As it is the most prescriptive way to code it is classified as imperative. |
|||
*[[Scalar programming]], compared to [[Array programming]] |
|||
*[[Structured programming]], compared to [[unstructured programming]] |
|||
It is sometimes called the [[first-generation programming language]]. |
|||
*[[Tree programming]] |
|||
=== Assembly === |
|||
*[[Value-level programming]], compared to [[function-level programming]] |
|||
*[[Metaprogramming]] |
|||
[[Assembly language]] introduced mnemonics for machine instructions and [[memory address]]es. Assembly is classified as imperative and is sometimes called the [[second-generation programming language]]. |
|||
In the 1960s, assembly languages were developed to support library COPY and quite sophisticated conditional macro generation and preprocessing abilities, CALL to [[subroutine]], external variables and common sections (globals), enabling significant code re-use and isolation from hardware specifics via the use of logical operators such as READ/WRITE/GET/PUT. Assembly was, and still is, used for time-critical systems and often in [[embedded system]]s as it gives the most control of what the machine does. |
|||
=== Procedural languages === |
|||
[[Procedural language]]s, also called the [[third-generation programming language]]s are the first described as [[high-level programming language|high-level languages]]. They support vocabulary related to the problem being solved. For example, |
|||
* COmmon Business Oriented Language ([[COBOL]]){{snd}} uses terms like [[computer file|file]], [[move (command)|move]] and [[copy (command)|copy]]. |
|||
* FORmula TRANslation ([[FORTRAN]]){{snd}} using [[mathematical]] language terminology, it was developed mainly for scientific and engineering problems. |
|||
* ALGOrithmic Language ([[ALGOL]]){{snd}} focused on being an appropriate language to define [[algorithm]]s, while using mathematical language terminology, targeting scientific and engineering problems, just like FORTRAN. |
|||
* Programming Language One ([[PL/I]]){{snd}} a hybrid commercial-scientific general purpose language supporting [[pointer (computer programming)|pointer]]s. |
|||
* Beginners All purpose Symbolic Instruction Code ([[BASIC]]){{snd}} it was developed to enable more people to write programs. |
|||
* [[C (programming language)|C]]{{snd}} a general-purpose programming language, initially developed by [[Dennis Ritchie]] between 1969 and 1973 at [[AT&T Bell Labs]]. |
|||
These languages are classified as procedural paradigm. They directly control the step by step process that a computer program follows. The [[efficacy]] and [[algorithmic efficiency|efficiency]] of such a program is therefore highly dependent on the programmer's skill. |
|||
=== Object-oriented programming === |
|||
{{Main|Object-oriented programming}} |
|||
In attempt to improve on procedural languages, [[object-oriented programming]] (OOP) languages were created, such as [[Simula]], [[Smalltalk]], [[C++]], [[Eiffel (programming language)|Eiffel]], [[Python (programming language)|Python]], [[PHP]], [[Java (programming language)|Java]], and [[C Sharp (programming language)|C#]]. In these languages, [[data]] and methods to manipulate the data are in the same code unit called an [[object (computer science)|object]]. This [[Encapsulation (computer programming)|encapsulation]] ensures that the only way that an object can access data is via ''[[Method (computer programming)|methods]]'' of the object that contains the data. Thus, an object's inner workings may be changed without affecting code that uses the object. |
|||
There is [[Object-oriented programming#Criticism|controversy]] raised by [[Alexander Stepanov]], [[Richard Stallman]]<ref>{{cite web|url=http://groups.google.com/group/comp.emacs.xemacs/browse_thread/thread/d0af257a2837640c/37f251537fafbb03?lnk=st&q=%22Richard+Stallman%22+oop&rnum=5&hl=en#37f251537fafbb03|title=Mode inheritance, cloning, hooks & OOP (Google Groups Discussion)}}</ref> and other programmers, concerning the efficacy of the OOP paradigm versus the procedural paradigm. The need for every object to have associative methods leads some skeptics to associate OOP with [[software bloat]]; an attempt to resolve this dilemma came through [[Polymorphism (computer science)|polymorphism]]. |
|||
Although most OOP languages are third-generation, it is possible to create an object-oriented assembler language. [[High Level Assembly]] (HLA) is an example of this that fully supports advanced data types and object-oriented assembly language programming{{snd}} despite its early origins. Thus, differing programming paradigms can be seen rather like ''motivational [[meme]]s'' of their advocates, rather than necessarily representing progress from one level to the next.{{Citation needed|date=March 2018}} Precise comparisons of competing paradigms' efficacy are frequently made more difficult because of new and differing terminology applied to similar entities and processes together with numerous implementation distinctions across languages. |
|||
=== Declarative languages === |
|||
A [[declarative programming]] program describes what the problem is, not how to solve it. The program is structured as a set of properties to find in the expected result, not as a procedure to follow. Given a database or a set of rules, the computer tries to find a solution matching all the desired properties. An archetype of a declarative language is the [[fourth-generation programming language|fourth generation language]] [[SQL]], and the family of functional languages and logic programming. |
|||
[[Functional programming]] is a subset of declarative programming. Programs written using this paradigm use [[subroutine|functions]], blocks of code intended to behave like [[function (mathematics)|mathematical functions]]. Functional languages discourage changes in the value of variables through [[assignment (computer science)|assignment]], making a great deal of use of [[recursion (computer science)|recursion]] instead. |
|||
The [[logic programming]] paradigm views computation as [[automated reasoning]] over a body of knowledge. Facts about the [[domain (software engineering)|problem domain]] are expressed as logic formulas, and programs are executed by applying [[inference rule]]s over them until an answer to the problem is found, or the set of formulas is proved inconsistent. |
|||
=== Other paradigms === |
|||
[[Symbolic programming]] is a paradigm that describes programs able to manipulate formulas and program components as data.<ref name="symbolic-programming-lisp"/> Programs can thus effectively modify themselves, and appear to "learn", making them suited for applications such as [[artificial intelligence]], [[expert system]]s, [[natural-language processing]] and computer games. Languages that support this paradigm include [[Lisp (programming language)|Lisp]] and [[Prolog]].<ref>{{cite web |
|||
|url=http://www.allbusiness.com/glossaries/symbolic-programming/4950308-1.html |
|||
|title=Business glossary: Symbolic programming definition |
|||
|access-date=2014-07-30 |
|||
|website=allbusiness.com |
|||
}}</ref> |
|||
[[Differentiable programming]] structures programs so that they can be [[Differentiation (mathematics)|differentiated]] throughout, usually via [[automatic differentiation]].<ref>{{Citation|last1=Wang|first1=Fei|title=Backpropagation with Callbacks: Foundations for Efficient and Expressive Differentiable Programming|date=2018|url=http://papers.nips.cc/paper/8221-backpropagation-with-callbacks-foundations-for-efficient-and-expressive-differentiable-programming.pdf|work=Advances in Neural Information Processing Systems 31|pages=10201–10212|editor-last=Bengio|editor-first=S.|publisher=Curran Associates, Inc.|access-date=2019-02-13|last2=Decker|first2=James|last3=Wu|first3=Xilun|last4=Essertel|first4=Gregory|last5=Rompf|first5=Tiark|editor2-last=Wallach|editor2-first=H.|editor3-last=Larochelle|editor3-first=H.|editor4-last=Grauman|editor4-first=K.}}</ref><ref name="innes">{{Cite journal|last1=Innes|first1=Mike|date=2018|title=On Machine Learning and Programming Languages|url=http://www.sysml.cc/doc/37.pdf|journal=SysML Conference 2018|access-date=2019-02-13|archive-url=https://web.archive.org/web/20180920175619/http://www.sysml.cc/doc/37.pdf|archive-date=2018-09-20|url-status=dead}}</ref> |
|||
[[Literate programming]], as a form of [[imperative programming]], structures programs as a human-centered web, as in a [[hypertext]] essay: documentation is integral to the program, and the program is structured following the logic of prose exposition, rather than compiler convenience. |
|||
[[Symbolic programming]] techniques such as [[reflective programming]] (reflection), which allow a program to refer to itself, might also be considered as a programming paradigm. However, this is compatible with the major paradigms and thus is not a real paradigm in its own right. |
|||
== See also == |
== See also == |
||
{{Portal|Computer programming}} |
|||
* [[ARS based programming]] |
|||
* [[Grammar-oriented programming]] |
|||
{{div col}} |
|||
[[Category:programming paradigms|!]] |
|||
[[ |
* [[Domain-specific language]] |
||
* [[Flow-based programming]] |
|||
* [[Modeling language]] |
|||
* [[Programming domain]] |
|||
* [[Turing completeness]] |
|||
* [[Von Neumann programming languages]] |
|||
{{div col end}} |
|||
== References == |
|||
[[bg:Парадигма на програмиране]] |
|||
{{Reflist}} |
|||
[[ca:Paradigma de programació]] |
|||
[[da:Programmeringsparadigme]] |
|||
==External links== |
|||
[[de:Programmierparadigma]] |
|||
{{Commons category|Programming language by paradigm}} |
|||
[[es:Paradigma de programación]] |
|||
*[http://www.info.ucl.ac.be/~pvr/paradigms.html Classification of the principal programming paradigms] |
|||
[[fr:Paradigme (programmation)]] |
|||
*[http://www.janeve.me/articles/understanding-programming-paradigms How programming paradigms evolve and get adopted?] |
|||
[[gl:Paradigma de programación]] |
|||
[[ko:프로그래밍 패러다임]] |
|||
{{Navboxes |
|||
[[id:Paradigma pemrograman]] |
|||
| title= Software engineering |
|||
[[it:Paradigma di programmazione]] |
|||
| state= collapsed |
|||
[[he:פרדיגמת תכנות]] |
|||
| list= |
|||
[[lv:Programmēšanas paradigma]] |
|||
{{Computer language}} |
|||
[[hu:Programozási paradigmák]] |
|||
{{Software engineering}} |
|||
[[nl:Programmeerparadigma]] |
|||
{{Computer science}} |
|||
[[ja:プログラミングパラダイム]] |
|||
}} |
|||
[[pl:Paradygmat programowania]] |
|||
{{Navboxes |
|||
[[pt:Paradigma de programação]] |
|||
| title= Programming |
|||
[[ru:Парадигма программирования]] |
|||
| state= collapsed |
|||
[[sv:Programmeringsparadigm]] |
|||
| list= |
|||
[[ta:நிரலாக்க கருத்தோட்டம்]] |
|||
{{Programming paradigms navbox}} |
|||
[[uk:Парадигма програмування]] |
|||
{{Programming language generations}} |
|||
[[zh:编程范型]] |
|||
{{Major programming languages}} |
|||
{{Types of programming languages}} |
|||
}} |
|||
{{Computer_science}} |
|||
{{authority control}} |
|||
{{DEFAULTSORT:Programming paradigm}} |
|||
[[Category:Programming paradigms| ]] |
|||
[[Category:Programming language classification]] |
|||
[[Category:Programming language topics]] |
Latest revision as of 20:27, 2 January 2025
A programming paradigm is a relatively high-level way to conceptualize and structure the implementation of a computer program. A programming language can be classified as supporting one or more paradigms.[1]
Paradigms are separated along and described by different dimensions of programming. Some paradigms are about implications of the execution model, such as allowing side effects, or whether the sequence of operations is defined by the execution model. Other paradigms are about the way code is organized, such as grouping into units that include both state and behavior. Yet others are about syntax and grammar.
Some common programming paradigms include (shown in hierarchical relationship):[2][3][4]
- Imperative – code directly controls execution flow and state change, explicit statements that change a program state
- procedural – organized as procedures that call each other
- object-oriented – organized as objects that contain both data structure and associated behavior, uses data structures consisting of data fields and methods together with their interactions (objects) to design programs
- Class-based – object-oriented programming in which inheritance is achieved by defining classes of objects, versus the objects themselves
- Prototype-based – object-oriented programming that avoids classes and implements inheritance via cloning of instances
- Declarative – code declares properties of the desired result, but not how to compute it, describes what computation should perform, without specifying detailed state changes
- functional – a desired result is declared as the value of a series of function evaluations, uses evaluation of mathematical functions and avoids state and mutable data
- logic – a desired result is declared as the answer to a question about a system of facts and rules, uses explicit mathematical logic for programming
- reactive – a desired result is declared with data streams and the propagation of change
- Concurrent programming – has language constructs for concurrency, these may involve multi-threading, support for distributed computing, message passing, shared resources (including shared memory), or futures
- Actor programming – concurrent computation with actors that make local decisions in response to the environment (capable of selfish or competitive behaviour)
- Constraint programming – relations between variables are expressed as constraints (or constraint networks), directing allowable solutions (uses constraint satisfaction or simplex algorithm)
- Dataflow programming – forced recalculation of formulas when data values change (e.g. spreadsheets)
- Distributed programming – has support for multiple autonomous computers that communicate via computer networks
- Generic programming – uses algorithms written in terms of to-be-specified-later types that are then instantiated as needed for specific types provided as parameters
- Metaprogramming – writing programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime
- Template metaprogramming – metaprogramming methods in which a compiler uses templates to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled
- Reflective programming – metaprogramming methods in which a program modifies or extends itself
- Pipeline programming – a simple syntax change to add syntax to nest function calls to language originally designed with none
- Rule-based programming – a network of rules of thumb that comprise a knowledge base and can be used for expert systems and problem deduction & resolution
- Visual programming – manipulating program elements graphically rather than by specifying them textually (e.g. Simulink); also termed diagrammatic programming
Overview
[edit]Programming paradigms come from computer science research into existing practices of software development. The findings allow for describing and comparing programming practices and the languages used to code programs. For perspective, other fields of research study software engineering processes and describe various methodologies to describe and compare them.
A programming language can be described in terms of paradigms. Some languages support only one paradigm. For example, Smalltalk supports object-oriented and Haskell supports functional. Most languages support multiple paradigms. For example, a program written in C++, Object Pascal, or PHP can be purely procedural, purely object-oriented, or can contain aspects of both paradigms, or others.
When using a language that supports multiple paradigms, the developer chooses which paradigm elements to use. But, this choice may not involve considering paradigms per se. The developer often uses the features of a language as the language provides them and to the extent that the developer knows them. Categorizing the resulting code by paradigm is often an academic activity done in retrospect.
Languages categorized as imperative paradigm have two main features: they state the order in which operations occur, with constructs that explicitly control that order, and they allow side effects, in which state can be modified at one point in time, within one unit of code, and then later read at a different point in time inside a different unit of code. The communication between the units of code is not explicit.
In contrast, languages in the declarative paradigm do not state the order in which to execute operations. Instead, they supply a number of available operations in the system, along with the conditions under which each is allowed to execute.[7] The implementation of the language's execution model tracks which operations are free to execute and chooses the order independently. More at Comparison of multi-paradigm programming languages.
In object-oriented programming, code is organized into objects that contain state that is owned by and (usually) controlled by the code of the object. Most object-oriented languages are also imperative languages.
In object-oriented programming, programs are treated as a set of interacting objects. In functional programming, programs are treated as a sequence of stateless function evaluations. When programming computers or systems with many processors, in process-oriented programming, programs are treated as sets of concurrent processes that act on a logical shared data structures.
Many programming paradigms are as well known for the techniques they forbid as for those they support. For instance, pure functional programming disallows side-effects, while structured programming disallows the goto construct. Partly for this reason, new paradigms are often regarded as doctrinaire or overly rigid by those accustomed to older ones.[8] Yet, avoiding certain techniques can make it easier to understand program behavior, and to prove theorems about program correctness.
Programming paradigms can also be compared with programming models, which allows invoking an execution model by using only an API. Programming models can also be classified into paradigms based on features of the execution model.
For parallel computing, using a programming model instead of a language is common. The reason is that details of the parallel hardware leak into the abstractions used to program the hardware. This causes the programmer to have to map patterns in the algorithm onto patterns in the execution model (which have been inserted due to leakage of hardware into the abstraction). As a consequence, no one parallel programming language maps well to all computation problems. Thus, it is more convenient to use a base sequential language and insert API calls to parallel execution models via a programming model. Such parallel programming models can be classified according to abstractions that reflect the hardware, such as shared memory, distributed memory with message passing, notions of place visible in the code, and so forth. These can be considered flavors of programming paradigm that apply to only parallel languages and programming models.
Criticism
[edit]Some programming language researchers criticise the notion of paradigms as a classification of programming languages, e.g. Harper,[9] and Krishnamurthi.[10] They argue that many programming languages cannot be strictly classified into one paradigm, but rather include features from several paradigms. See Comparison of multi-paradigm programming languages.
History
[edit]Different approaches to programming have developed over time. Classification of each approach was either described at the time the approach was first developed, but often not until some time later, retrospectively. An early approach consciously identified as such is structured programming, advocated since the mid 1960s. The concept of a programming paradigm as such dates at least to 1978, in the Turing Award lecture of Robert W. Floyd, entitled The Paradigms of Programming, which cites the notion of paradigm as used by Thomas Kuhn in his The Structure of Scientific Revolutions (1962).[11] Early programming languages did not have clearly defined programming paradigms and sometimes programs made extensive use of goto statements. Liberal use of which lead to spaghetti code which is difficult to understand and maintain. This led to the development of structured programming paradigms that disallowed the use of goto statements; only allowing the use of more structured programming constructs.[12]
Languages and paradigms
[edit]Machine code
[edit]Machine code is the lowest-level of computer programming as it is machine instructions that define behavior at the lowest level of abstract possible for a computer. As it is the most prescriptive way to code it is classified as imperative.
It is sometimes called the first-generation programming language.
Assembly
[edit]Assembly language introduced mnemonics for machine instructions and memory addresses. Assembly is classified as imperative and is sometimes called the second-generation programming language.
In the 1960s, assembly languages were developed to support library COPY and quite sophisticated conditional macro generation and preprocessing abilities, CALL to subroutine, external variables and common sections (globals), enabling significant code re-use and isolation from hardware specifics via the use of logical operators such as READ/WRITE/GET/PUT. Assembly was, and still is, used for time-critical systems and often in embedded systems as it gives the most control of what the machine does.
Procedural languages
[edit]Procedural languages, also called the third-generation programming languages are the first described as high-level languages. They support vocabulary related to the problem being solved. For example,
- COmmon Business Oriented Language (COBOL) – uses terms like file, move and copy.
- FORmula TRANslation (FORTRAN) – using mathematical language terminology, it was developed mainly for scientific and engineering problems.
- ALGOrithmic Language (ALGOL) – focused on being an appropriate language to define algorithms, while using mathematical language terminology, targeting scientific and engineering problems, just like FORTRAN.
- Programming Language One (PL/I) – a hybrid commercial-scientific general purpose language supporting pointers.
- Beginners All purpose Symbolic Instruction Code (BASIC) – it was developed to enable more people to write programs.
- C – a general-purpose programming language, initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs.
These languages are classified as procedural paradigm. They directly control the step by step process that a computer program follows. The efficacy and efficiency of such a program is therefore highly dependent on the programmer's skill.
Object-oriented programming
[edit]In attempt to improve on procedural languages, object-oriented programming (OOP) languages were created, such as Simula, Smalltalk, C++, Eiffel, Python, PHP, Java, and C#. In these languages, data and methods to manipulate the data are in the same code unit called an object. This encapsulation ensures that the only way that an object can access data is via methods of the object that contains the data. Thus, an object's inner workings may be changed without affecting code that uses the object.
There is controversy raised by Alexander Stepanov, Richard Stallman[13] and other programmers, concerning the efficacy of the OOP paradigm versus the procedural paradigm. The need for every object to have associative methods leads some skeptics to associate OOP with software bloat; an attempt to resolve this dilemma came through polymorphism.
Although most OOP languages are third-generation, it is possible to create an object-oriented assembler language. High Level Assembly (HLA) is an example of this that fully supports advanced data types and object-oriented assembly language programming – despite its early origins. Thus, differing programming paradigms can be seen rather like motivational memes of their advocates, rather than necessarily representing progress from one level to the next.[citation needed] Precise comparisons of competing paradigms' efficacy are frequently made more difficult because of new and differing terminology applied to similar entities and processes together with numerous implementation distinctions across languages.
Declarative languages
[edit]A declarative programming program describes what the problem is, not how to solve it. The program is structured as a set of properties to find in the expected result, not as a procedure to follow. Given a database or a set of rules, the computer tries to find a solution matching all the desired properties. An archetype of a declarative language is the fourth generation language SQL, and the family of functional languages and logic programming.
Functional programming is a subset of declarative programming. Programs written using this paradigm use functions, blocks of code intended to behave like mathematical functions. Functional languages discourage changes in the value of variables through assignment, making a great deal of use of recursion instead.
The logic programming paradigm views computation as automated reasoning over a body of knowledge. Facts about the problem domain are expressed as logic formulas, and programs are executed by applying inference rules over them until an answer to the problem is found, or the set of formulas is proved inconsistent.
Other paradigms
[edit]Symbolic programming is a paradigm that describes programs able to manipulate formulas and program components as data.[4] Programs can thus effectively modify themselves, and appear to "learn", making them suited for applications such as artificial intelligence, expert systems, natural-language processing and computer games. Languages that support this paradigm include Lisp and Prolog.[14]
Differentiable programming structures programs so that they can be differentiated throughout, usually via automatic differentiation.[15][16]
Literate programming, as a form of imperative programming, structures programs as a human-centered web, as in a hypertext essay: documentation is integral to the program, and the program is structured following the logic of prose exposition, rather than compiler convenience.
Symbolic programming techniques such as reflective programming (reflection), which allow a program to refer to itself, might also be considered as a programming paradigm. However, this is compatible with the major paradigms and thus is not a real paradigm in its own right.
See also
[edit]References
[edit]- ^ "Multi-Paradigm Programming Language". Mozilla Developer Network. Mozilla Foundation. Jun 21, 2013. Archived from the original on 21 August 2013.
- ^ Nørmark, Kurt. Overview of the four main programming paradigms. Aalborg University, 9 May 2011. Retrieved 22 September 2012.
- ^ Frans Coenen (1999-10-11). "Characteristics of declarative programming languages". cgi.csc.liv.ac.uk. Archived from the original on 2014-02-27. Retrieved 2014-02-20.
- ^ a b Michael A. Covington (2010-08-23). "CSCI/ARTI 4540/6540: First Lecture on Symbolic Programming and LISP" (PDF). University of Georgia. Archived from the original (PDF) on 2012-03-07. Retrieved 2013-11-20.
- ^ Peter Van Roy (2009-05-12). "Programming Paradigms: What Every Programmer Should Know" (PDF). info.ucl.ac.be. Retrieved 2014-01-27.
- ^ Peter Van-Roy; Seif Haridi (2004). Concepts, Techniques, and Models of Computer Programming. MIT Press. ISBN 978-0-262-22069-9.
- ^ "Programming paradigms: What are the principles of programming?". IONOS Digitalguide. 20 April 2020. Archived from the original on Jun 29, 2022. Retrieved 2022-05-03.
- ^ Frank Rubin (March 1987). "'GOTO Considered Harmful' Considered Harmful" (PDF). Communications of the ACM. 30 (3): 195–196. doi:10.1145/214748.315722. S2CID 6853038. Archived from the original (PDF) on March 20, 2009.
- ^ Harper, Robert (1 May 2017). "What, if anything, is a programming-paradigm?". FifteenEightyFour. Cambridge University Press.
- ^ Krishnamurthi, Shriram (November 2008). "Teaching programming languages in a post-linnaean age". ACM SIGPLAN Notices. 43 (11). ACM: 81–83. doi:10.1145/1480828.1480846. S2CID 35714982..
- ^ Floyd, R. W. (1979). "The paradigms of programming". Communications of the ACM. 22 (8): 455–460. doi:10.1145/359138.359140.
- ^ Soroka, Barry I. (2006). Java 5: Objects First. Jones & Bartlett Learning. ISBN 9780763737207.
- ^ "Mode inheritance, cloning, hooks & OOP (Google Groups Discussion)".
- ^ "Business glossary: Symbolic programming definition". allbusiness.com. Retrieved 2014-07-30.
- ^ Wang, Fei; Decker, James; Wu, Xilun; Essertel, Gregory; Rompf, Tiark (2018), Bengio, S.; Wallach, H.; Larochelle, H.; Grauman, K. (eds.), "Backpropagation with Callbacks: Foundations for Efficient and Expressive Differentiable Programming" (PDF), Advances in Neural Information Processing Systems 31, Curran Associates, Inc., pp. 10201–10212, retrieved 2019-02-13
- ^ Innes, Mike (2018). "On Machine Learning and Programming Languages" (PDF). SysML Conference 2018. Archived from the original (PDF) on 2018-09-20. Retrieved 2019-02-13.