DEV Community

Discussion on: Function vs Object

sebbdk profile image
Sebastian Vargr • Edited on

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()

vlasales profile image
Vlastimil Pospichal

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

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

daveparr profile image
Dave Parr

From Nidavellir import mjölnir as stormbreaker


olvnikon profile image

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 =ölnir));