Date post: | 14-Apr-2017 |
Category: |
Technology |
Upload: | mailjet |
View: | 524 times |
Download: | 0 times |
Functional Programming with ES6
Guillaume Badi • 25.11.2015
Me ?
Developer Evangelist @Mailjet
Student @42
Node.JS fanboy
Autodidact
Twitter: @WeshGuillaume
This is the Government
(l’état, c’est moi)
Documents
Money
When the money comes from the “Companies”, we have a set of rules describing the way it has to be distributed.
The hierarchical approach makes it easy to visualize but hard to improve.
Problems
Nobody fully understands it
It requires tons of people to maintain
Adding new institutions is a pain
Changing something in one area requires changes in many other areas
Economists call it Bureaucracy
We call it Object Oriented programming
This is a structured mess
We want a function that takes the existing agents and returns new ones, when the money comes in.
Documents
Money
We could model it differently.
Companies1
Population1
Government1
Companies2
Population2
Government2
“It's not who I am underneath, but what I do that defines me.” - The Batman
Object Oriented Programming is good at describing things
Describing data.
Describing patterns
And by extension…
CAF = (salary, rent) => [Function]
Pole Emploi = (workPeriod) => [Function]
Institutions = (salary, rent, workPeriod) => [Function]
We want to “transform” our data, the mathematical way.
Functions should be pure. Understand “context-free”.
Functions are data that operate on some other data. It makes your code easy to test
Why is ES6 good for the Job ?
Function syntax is now short and clear
Returning functions is pure poetry
Same code in Go
Promises. comma.
Promises. period.
A lot of people just hate JavaScript
But precisely with this syntax, We have the choice to adopt a Java coding style...
Flatten a nested array
...Or a cleaner functional style
Functional programming is not simple. It requires
discipline and… meditation
Immutable data is one of the keys
Use map/filter/reduce when you can
If you have to use the words “and” or “then”, to describe your function, split it.
Documents
Money
We could model it differently.
Companies1
Population1
Government1
Companies2
Population2
Government2
Merci
Github: GuillaumebadiTwitter: @WeshGuillaume