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: Guillaumebadi Twitter: @WeshGuillaume

Functional programming with ES6

Editor's Notes

  • #10 la bureaucratie désigne un pouvoir sans direction qui se caractérise par des règles strictes, la division des responsabilités et une forte hiérarchie.
  • #31 Parler de la syntax: const, let, fat arrow functions etc compared to es5
  • #34 meditation: you might have to stare at your code (really long some times) to figure out how the data flows and once your function works, and pass the tests, bugs becomes rare
  • #36 In OO, we call it states. But when your variables change, bugs are becoming hard to find and fix.
  • #38 It ensures immutability
  • #39 add example