Imperative vs Declarative programming
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697691/yelster_digital_-_1000x1000_72dpi_-_original_2.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697695/Solocal_NEW_logo_-_1500x500_72dpi_-_ORIGINAL.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697841/Screen_Shot_2019-01-22_at_2.34.41_PM.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697717/nikola-jovanovic-198375-unsplash.jpg)
Photo by Nikola Jovanovic on Unsplash
Photo by Alok Sharma on Unsplash
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697776/alok-sharma-693658-unsplash.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697762/jean-philippe-delberghe-785844-unsplash.jpg)
Photo by Jean-Philippe Delberghe on Unsplash
SELECT * FROM Pages WHERE publisher_id=’facebook’;
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697724/florian-olivo-1169465-unsplash.jpg)
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!
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697691/yelster_digital_-_1000x1000_72dpi_-_original_2.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/594010/images/5697695/Solocal_NEW_logo_-_1500x500_72dpi_-_ORIGINAL.png)
Imperative vs Declarative programming
By Maciej Jordanek
Imperative vs Declarative programming
- 338