DEV Community

John Kazer
John Kazer

Posted on

2

Why functional programming? Stay in control

As I delve a bit more into the experience of converting myself into a semi-literate functional programmer, I still wonder what is the point.

Well, one interesting realisation occurred today and it is about control.

I was looking at some code, a straightforward JavaScript array.forEach construct. I thought about what was needed to convert it into something more functional - e.g. a array.map. What would happen? I'd need a return value to use as the logical effect of the function. What was I doing right now? It was hard to say - need to read the code and find out what the effect really is.

And then it hit me - using forEach means I was losing control of the code. It didn't feel 'safe' somehow. If I was asking for a return value then I'd still be in control because then I can do something with it. Using forEach gives all that responsibility away. I have to trust the called function to do the right thing.

Maybe this is a consequence of writing functional code and my emotional response to code is changing?

Hard to say, but it gave me some insight into the psychology of code wars and declarative (functional) vs procedural approaches.

Conclusion: Functional programmers like control and certainty, procedural programmers are more chilled (or maybe more anxious).

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
mjsarfatti profile image
Manuele J Sarfatti โ€ข

Love this take!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay