DEV Community

loading...

Discussion on: Functional Programming vs OOPS : Explain Like I'm Five

Collapse
gmartigny profile image
Guillaume Martigny

Functional is based on functions and OOP (Object Oriented Programming) is based on objects. It's two distinct ways to write code. It's not the only two nor they are mutually exclusive. While OOP tends to replicate the real world with objects you act on, functional is way too abstract for a five year old. It's more like a flow of actions rather than objects interacting with each others.

Consider this recipe:

functional

const crepe = step([
  () => [getFlour(300), getEggs(3), getMilk(60)],
  mix,
  cook,
]);

OOP

const flour = new Ingredient("flour", 300);
const eggs = new Ingredient("egg", 3);
const milk = new Ingredient("milk", 60);

const crepe = new Recipe();
crepe.mix(flour, eggs, milk).cook();