Imperative vs Declarative programming

Maciej Jordanek, 22.01.2019

How?

What?

1. Write a function called double which takes in an array of numbers and returns a new array after doubling every item in that array. double([1,2,3]) -> [2,4,6] 

2. Write a function called add which takes in an array and returns the result of adding up every item in the array. add([1,2,3]) -> 6

Photo by Nikola Jovanovic on Unsplash

Photo by Alok Sharma on Unsplash

SELECT * FROM Pages WHERE publisher_id=’facebook’;

Photo by Florian Olivo on Unsplash

Declarative programming is ...

“the act of programming in languages that conform to the mental model of the developer rather than the operational model of the machine”.

Declarative Programming is programming with declarations, i.e. declarative sentences.

The declarative property is where there can exist only one possible set of statements that can express each specific modular semantic.The imperative property is the dual, where semantics are inconsistent under composition and/or can be expressed with variations of sets of statements.

Declarative languages contrast with imperative languages which specify explicit manipulation of the computer’s internal state; or procedural languages which specify an explicit sequence of steps to follow.

In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow.

Pro

  • "What?"
  • Easy to reason about
  • No state mutation
  • Can be introduced gradually
  • Readability**

** Make sure everyone in your team is aligned.

Contra

  • Readability**
  • Challenging at first
  • Different way of thinking

** Make sure everyone in your team is aligned.

"Odds are there isn’t a lower hanging fruit to improve your codebase than making it more functional." - Tyler McGinnis

Thank you!

Imperative vs Declarative programming

By Maciej Jordanek

Imperative vs Declarative programming

  • 338