Hacker News new | ask | show | jobs
by guccimane 5172 days ago
Oh, stop. I'm tired of hearing about "smug" being the worst thing ever. Too easy to toss this insult around.

Instead, personally my issue with functional programming is the aversion to side effects. It seems to cause a lot of weird contortions, when the whole reason we make software in the first place is for the side effects. Programming in a functional style brings with it a lot of wonderful, powerful ideas. But that one has always struck me as unfortunate.

3 comments

I couldn't disagree more.

I find that the aversion to side effects even when working in imperative languages is one of the most useful things I've learned from functional programming.

It is true that, at one level of abstraction, we write programs for their side effects. However, it is also true that having the right side effects is extremely important - so important that a program with the wrong side effects can easily be worse than no program at all. From that perspective, a focus on minimizing, containing and controlling side effects is very valuable. And an aversion to side effects is a good way to sharpen your focus on that.

> I couldn't disagree more.

I know. Trust me, I know.

While it's true that the output/observable behavior is what we want out of a program, whether the internals rely on side effects, strictly speaking, isn't relevant to producing useful things for the users.

I won't deny that sometimes, a lack of side effects results in weird contortions, but there are ways around it and benefits that make up for it. Since side-effect-free functions are way easier to predict, debugging time is much shorter in FP, I find. Monads, while difficult to grok at first, are elegant ways to get around side effects in pure FP languages.

Or, just go with my personal favorite solution, use an FP language that's not pure (e.g., most Lisps). They tend to encourage side-effect-free and/or state-free programs, but do not strictly require it. This gives you the best of both (IMNSHO); 80-90% of your code is side-effect-free and easier to debug, and the side-effect code is relatively contained and straightforward (in an imperative sense).

Banning side-effects like IO does create the need for odd contortions, but having less side-effects and little or no mutable data makes error recovery and debugging so much nicer.