A Brief Survey of “Programming Paradigms”

Jing Chen
7 min readApr 11, 2019

--

A figure showing taxonomy of programming paradigms. Cited from Van Roy, “Programming Paradigms for Dummies,” page 13, figure 2, see https://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf.

Introduction: Imperative vs. Declarative Programming

I first encountered the term “Programming Paradigms” yesterday when I was in the lecture on JavaScript’s iterators and higher order functions. In the class, we learned the features of two programming paradigms: imperative vs. declarative. The former specifies the procedure, telling the computer how to do, while the latter tells the computer what to do. The code below, for example, shows the differences between the two.

//Imperative programming
total = function(numbers){
let total = 0
numbers.forEach(function(number){
total = total + number
})
return total
}
//Declarative programming
average = function(numbers){
return total(numbers) / numbers.length
}

Out of curiosity, after a single Google research online, it appears that there are actually more than 2 programming paradigms. Then later in the afternoon, in the lab that requires us to write “pure functions” for JavaScript, I encountered another term — “functional programming paradigm.”

In fact, according to “Programming Paradigms for Dummies: What Every Programmer Should Know,” we can have “almost 30 useful programming paradigms.” (Van Roy, page 9). Object-oriented, a term that I am very familiar with, is also considered a type of programming paradigms.

In this post, I would like to dive deeper into the topic programming paradigm, trying to offer a brief survey of the topic and its related terms. It seems that questions related to programming paradigm often appear in JavaScript interviews as mentioned in this post and here. Therefore, a brief survey of programming paradigms might be helpful for my understanding and learning of programming languages.

“Programming Paradigm”: A Term’s History

According to Wikipedia, “programming paradigms are a way to classify programming languages based on their features.” But I was still confused after reading the Wikipedia definition. So I tried to understand the word by tracing the history of this term.

In fact, when I first heard “Programming Paradigm,” it immediately reminds me of another term used in academic studies on the history of science — “Paradigm Shift,” a term coined by Thomas S. Kuhn in his 1962 book The Structure of Scientific Revolutions, where Kuhn defines “paradigms” as achievements that were (1) “sufficiently unprecedented to attract an enduring group of adherents away from competing modes of scientific activity.” (2) “Simultaneously, it was sufficiently open-ended to leave all sorts of problems for the redefined group of practitioners to resolve.” According to Kuhn, paradigms “provide models from which spring particular coherent traditions of scientific research.” (Kuhn, page 10)

In 1979, by borrowing Kuhn’s notion, in “The Paradigms of Programming,” Robert W. Floyd formally proposed the concept “Programming Paradigm”. He first evaluated the popular “structured programming paradigm” in the 1960s and the 1970s. According to him, “structured programming paradigm” adapted “the method of levels of abstraction, or of information binding.” (Floyd, page 456), while “a paradigm at an even higher level of abstraction than the structured programming paradigm is the construction of a hierarchy of languages, where programs in the highest level language operate on the most abstract objects, and are translated into programs on the next lower level language.” (Ibid., page 458) He also mentions that different languages support different paradigms, either weakly support or fully support: “When a language makes a paradigm convenient, I will say the language supports the paradigm. When a language makes a paradigm feasible, but not convenient, I will say the language weakly supports the paradigm.” (Ibid.)

Therefore, given the history of the term, I was able to understand the term “Programming Paradigm” better. “Programming Paradigm” is different from “Programming Model.” It provides the model. The differentiation of programming paradigms is based on each paradigm’s level of abstraction. Programming languages support paradigms. Most modern programming languages support multiple paradigms.

Major Paradigms

Then what are the major paradigms? Generally speaking, imperative and declarative are two basic types. Besides, there are other paradigms that are generally considered subtypes of the two types, which is an oversimplified misleading understanding of the taxonomy. Anyway, here are some major programming paradigms:

  • Imperative: structured, procedural, object-oriented, etc.
  • Declarative: functional, logic, etc.

In addition to the 2 basic types, there are many other types of paradigms such as “concurrent,” “generic,” etc. For a detailed list of programming paradigms, take a look at the textbox on the right side of this Wikipedia piece.

Here I summarized the meaning for the 5 subtypes of the imperative and declarative paradigms listed above, according to their Wikipedia pages:

1. structured programming: extensive use of the structured control flow constructs of selection (if/then/else) and repetition (while and for), block structures, and subroutines.

2. procedural programming: structured programming + procedures (that are also known as routines, subroutines, or functions, simply contain a series of computational steps to be carried out).

3. object-oriented programming: based on the concept of “objects”, which can contain data, in the form of fields (often known as attributes), and code, in the form of procedures (often known as methods). An object’s procedures that can access and often modify the data fields of the object with which they are associated.

4. functional programming: a declarative programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.

5. logic programming: largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem domain.

Multi-Paradigm Languages

Nowadays, many modern languages support multiple paradigms. For example, JavaScript is “a prototype-based, multi-paradigm scripting language that is dynamic, and supports object-oriented, imperative, and functional programming styles.” Given the official definition, JavaScript supports at least 3 programming paradigms: object-oriented, imperative, and functional (a subtype of declarative programming).

Likewise, Ruby is also a multi-paradigm language. According to Wiki, “Ruby is a dynamic, interpreted, reflective, object-oriented, general-purpose programming language… It supports multiple programming paradigms, including functional, object-oriented, and imperative.” Like JavaScript, it also supports at least 3 programming paradigms: object-oriented, imperative, and functional.

Then how about other languages? It seems that if you type “is Python a functional language,” then many related search questions popped up. The questions could be “is SQL an imperative language?” or “is C++ an imperative language” and so on. People are always eager to know different languages’ paradigms. After checking 8 programming languages’ official documentation, for my own convenience, here I am summarizing programming paradigms supported by 8 frequently-used programming languages:

  • C: imperative, procedural
  • C++: imperative, object-oriented, generic, functional style(not functional)
  • C#: imperative, declarative, functional, generic, object-oriented(class-based), component-oriented
  • Java: concurrent, class-based, functional(Java8)
  • JavaScript: imperative, functional, object-oriented
  • Python: imperative, functional, procedural, object-oriented
  • Ruby: imperative, functional, object-oriented
  • SQL: declarative, data-driven

Back to JavaScript…

Back to the paradigms supported by JavaScript. Of the three, it seems hard to understand “functional programming” and the related term “pure function” that characterizes this paradigm. With the help of some online readings (check this and this), I finally figured out “pure function” and “functional programming.”

JavaScript supports “functional programming” while JavaScript is not a purely functional programming language. In functional programming, data is immutable. According to this brief summary, pure function (1)“never changes any of the parameters that get passed to it by reference (in JS, objects, and arrays)” as parameters should be considered immutable. Moreover, (2)“the return value of a pure function is not influenced by anything else than its input parameters. (3)During its execution, a pure function does not change anything outside of it(side effects).” The code below provides a simple example of a pure function:

//pure function//1. return value: not influenced by anything else other than parameters
//2. function never changes the argument
//3. does not change anything outside of the function.
function pure(num){
return num * 3
}

So, now after a brief survey of programming paradigms, I could finally understand these new terms related to programming paradigms in a better way. Each paradigm in fact presents a different approach to solve programming problems, as well as a different style for programmers to write code. A good understanding of programming paradigms, thus, would allow us, the programmers, to make better choices when writing code.

References

--

--

Jing Chen

Avid learner of new tech stuff. Coding bootcamp graduate.