Paradigm #
A programming paradigm is a way to write programs. Paradigms include:
- imperative programming,
- object-oriented programming,
- functional programming,
- logical programming,
- etc.
Programming languages are often categorized based on the paradigms that they support.
Disclaimer. The boundaries of a paradigm are not always clear, and can be subjective. For this reason, we will (cautiously) borrow descriptions from Wikipedia.
Imperative programming #
Languages #
The most widely used programming languages are imperative.
Examples. Imperative languages include (in alphabetical order):
language observations C and C++ Most influential and oldest (1972 and 1985) languages in this list.
Still widely used, notably when high performance is needed.
C++ extends C with object-oriented features.C# Unrelated to C/C++.
Heavily influenced by Java.Go Java Largely influenced by C++ JavaScript Unrelated to Java.
Widely used for web applications (client side).Kotlin Interoperable with Java.
Popular choice for Android applications.Lua Perl PHP Python Widely used as a high-level interface for data science/machine learning. Ruby Rust Heir apparent to C/C++.
Growing appeal.Scala Extends Java with functional features. TypeScript Extends JavaScript with types. Visual Basic
Description #
From Wikipedia:
“Imperative programming focuses on describing how a program operates step by step […]. The term is often used in contrast to declarative programming, which focuses on what the program should accomplish without specifying all the details of how the program should achieve the result.”
Warning. The distinction between imperative and declarative programming (a.k.a. “how” versus “what”) is not binary, but a spectrum. Some languages (or programs) are more imperative, while others are more declarative.
Similarities. Imperative languages tend to share similar:
- elementary operations, e.g. variable assignment,
- control structures: “if/then/else” statements, loops, method calls, etc.
- data structures: arrays, linked lists, associative arrays, etc.
As a consequence, imperative algorithms can be described with pseudocode, in a language-independent fashion.
Object-oriented programming (OOP) #
Languages #
Object-oriented languages are (usually) also imperative.
Examples. Object-oriented languages include:
- C++,
- C#,
- Java/Kotlin/Scala,
- Ruby,
- Visual Basic.
Besides, many imperative languages that are not in this list provide some object-oriented features: e.g. Javascript/Typescript, Python or Rust.
Description #
From Wikipedia:
“An OOP computer program consists of objects that interact with one another. […] In class-based programming, the most common type of OOP, an object is an instance of a class. […] Classes may inherit from other classes, creating a hierarchy of classes.”
Application. OOP is widely used to structure moderate to large-size projects.
Functional programming #
Languages #
Functional languages are not as widely adopted as imperative ones.
Examples. Functional languages include:
- Elm,
- Erlang (and Elixir)
- Haskell,
- Lisp dialects: Common Lisp, F#, OCaml, etc.
- ML dialects: Clojure, Scheme, Standard ML, etc.
- PureScript,
- Scala.
Description #
From Wikipedia
“Functional programming has its roots in academia, evolving from the lambda calculus, a formal system of computation based only on functions.” “[…] By restricting side effects, programs can have fewer bugs, be easier to debug and test, and be more suited to formal verification.”
And from the Wikipedia page on programming paradigms:
Functional programming “avoids state and mutable data.”
Application. Many functional features have been borrowed by imperative languages (notably these last 15 years). The table below lists a few of them.
| functional feature | some imperative languages that support it (to some extent) |
|---|---|
| immutable data structures | C++, C#, Go, Java, Rust |
| higher-order functions | C++, C#, Go, Java, JavaScript, Python, Rust |
| anonymous functions | C++, C#, Go, Java, JavaScript, Python, Rust |
| data pipelines/streams (map, filter, fold, etc.) | C++, C#, Java, Python, Rust |
| lazy evaluation | C++, C#, Java, Python, Rust |
| pattern matching | C#, Java, PHP, Python, Rust |
| list comprehensions | Python |
Terminology. As a result, languages in this table are sometimes presented as “functional” (among other paradigms), even though they are primarily imperative or object-oriented.
Note. Java 8 (2014) introduced important functional features (notably the Stream API, which has seen a wide adoption).
This release of Java is sometimes credited with “modernising” the language.