News for hackers. Stuff that matters.
Re:Why functional programming matters by matwood on Tuesday April 18, 2017 @03:21PM (#14142019)
> Can anyone explain?

A quick example that can be faked in any language is a pure function [1]. The functions only inputs are the set of arguments, and from those arguments returns a side-effect free result. A pure function is easy to test and easy to reason about.

Contrast a pure function with an impure function that uses an objects internal state plus the arguments passed in to further tweak the state an/or return a result. It is immediately obvious the second is much harder to test and reason about. It becomes even more challenging when the object is thrown into a large system with a lot of moving parts.

Even before I really started learning about true functional programming, I had been writing 'pure' functions for years because they just made sense. Even internal private methods are simpler as pure functions. Shared state is evil for many reasons and should be avoided if possible.

[1] https://en.wikipedia.org/wiki/Pure_function

There are no comments on this comment yet.