1. 程式人生 > >Comparison of programming paradigms

Comparison of programming paradigms

event hid gen adl war reads tables lua together

Main paradigm approaches[edit]

The following are widely considered the main programming paradigms, as seen when measuring programming language popularity. There is some overlap between paradigms, inevitably, but the main features or identifiable differences are summarized in this table:

  • Imperative programming – defines computation as statements that change a program state.
  • Procedural programming, structured programming – specifies the steps a program must take to reach a desired state.
  • Declarative programming – defines program logic, but not detailed control flow.
  • Functional programming – treats programs as evaluating mathematical functions and avoids state and mutable data
  • Object-oriented programming (OOP) – organizes programs as objects: data structures consisting of datafields and methods together with their interactions.
  • Event-driven programming – program control flow is determined by events, such as sensor inputs or user actions (mouse clicks, key presses) or messages from other programs or threads.
  • Automata-based programming – a program, or part, is treated as a model of a finite state machine or any other formal automaton.

None of the main programming paradigms have a precise, globally unanimous definition, nor official international standard. Nor is there any agreement on which paradigm constitutes the best method to developing software. The subroutines that implement OOP methods may be ultimately coded in an imperative, functional, or procedural style that may, or may not, directly alter state on behalf of the invoking program.

ParadigmDescriptionMain traitsRelated paradigm(s)CritiqueExamples
Imperative Programs as statements that directly change computed state (datafields) Direct assignments, common data structures, global variables Edsger W. Dijkstra, Michael A. Jackson C, C++, Java, PHP, Python, Ruby
Structured A style of imperative programming with more logical program structure Structograms, indentation, no or limited use of goto statements Imperative C, C++, Java, Python
Procedural Derived from structured programming, based on the concept of modular programming or the procedure call Local variables, sequence, selection, iteration, and modularization Structured, imperative C, C++, Lisp, PHP, Python
Functional Treats computation as the evaluation of mathematical functions avoiding state and mutable data Lambda calculus, compositionality, formula, recursion, referential transparency, no side effects Declarative C++,[1] Clojure, Coffeescript,[2] Elixir, Erlang, F#, Haskell, Lisp, Python, Ruby, Scala, SequenceL, Standard ML, JavaScript
Event-drivenincluding time-driven Control flow is determined mainly by events, such as mouse clicks or interrupts including timer Main loop, event handlers, asynchronous processes Procedural, dataflow JavaScript, ActionScript, Visual Basic, Elm
Object-oriented Treats datafields as objects manipulated through predefined methods only Objects, methods, message passing, information hiding, data abstraction, encapsulation, polymorphism, inheritance, serialization-marshalling Procedural Here and[3][4][5] Common Lisp, C++, C#, Eiffel, Java, PHP, Python, Ruby, Scala, JavaScript[6][7]
Declarative Defines program logic, but not detailed control flow Fourth-generation languages, spreadsheets, report program generators SQL, regular expressions, CSS, Prolog, OWL, SPARQL
Automata-based programming Treats programs as a model of a finite state machine or any other formal automata State enumeration, control variable, state changes, isomorphism, state transition table Imperative, event-driven Abstract State Machine Language

Differences in terminology

https://en.wikipedia.org/wiki/Comparison_of_programming_paradigms

Comparison of programming paradigms