loading...

re: Function vs Object VIEW POST

FULL DISCUSSION
 

OOP has hammers, functional programming has the ability to smash things.

Advocates of OOP, like having specific things to smash with. Advocates of functional programming think just being able to smash is enough because they aren’t throwing thunderbolts, like hammers also can do.

When it comes down to it, if we measure by smash, both Hulk and Thor do it quite well.

It really just comes down to the style of smashing you like to do.

mjölnir.smash() or smash()

 

OOP: mjölnir.smash()
// mjölnir is an object

FP: mjölnir.smash()
// mjölnir is a namespace

 

From Nidavellir import mjölnir as stormbreaker

Stormbreaker.smash()

 

In FP functions without arguments are code smell because most probable they contain side effects. So in FP it would be:
const mjölnirSmash = smash(mjölnir);
const newGround = mjölnirSmash(currentGround);

Or with ADT something like this:
const ground = Functor(/* some data */);
const newGround = ground.map(smash(mjölnir));

Code of Conduct Report abuse