Science Loves Declarative Style [1]

… so why are you still coding in imperative style?

Yamac Eren Ay
8 min readMay 7, 2022

--

It is the first chapter of Science Loves Declarative Style, and you can navigate to the next chapter clicking here.

Imperative programming has been the most popular paradigm for a century.

Most of the technological breakthroughs are achieved using imperative programming languages such as Java, C/C++, JavaScript, Go.

We cannot really imagine how to program a simple for loop program without a for loop.

Recursion is — generally speaking — less intuitive and human-understandable than iteration.

Perhaps that’s why declarative programming is nowadays an uncommon paradigm that only a few of us know.

It is not difficult, but unintuitive, and we are not programmed to program recursively. In case you don’t know those programming paradigms:

Declarative programming is known as a superset of functional programming and logical programming, but it is sometimes interchangeably referred as functional programming due to its high popularity.

Logical programming is built on relations and predicates, and the variable assignment is achieved under unifications and resolutions ( = a depth-first search algorithm for finding any solution which suits well to the condition).

We will see more on functional programming in the next sections.

Key Features of Functional Programming

Source: https://www.xenonstack.com/insights/functional-programming

In general, Functional Programming has the following key features:

First-class functions: Everything is a function.

  • Variables and constants are also functions which don’t take any arguments.
  • So a function results always to a function when called.
  • With this in mind, a function can be also partial — intermediate states of a function are also functions.
  • For example: “=” with 2 arguments, checks whether both numbers are equal.
  • “=5” with one argument, checks whether a number is equal to 5.

--

--

Yamac Eren Ay

I love to write articles about the most underrated topics in computer science