Hacker News new | ask | show | jobs
by foldr 834 days ago
I think that's true when it comes to functional programming in the large (designing systems without lots of implicit mutable state), but less so when it comes to the code style of individual functions. For example, one of the following functions is written in a 'functional' style and the other is not, but they are equally easy to unit test:

    function getLongNames(names) {
        let longNames = [];
        for (const n of names) {
            if (n.length > 20)
                longNames.push(n)
        }
        return longNames;
    }

    function getLongNames(names) { return names.filter(n => n.length > 20); }
In this case the second implementation is clearly superior, as it avoids implementing array filtering de novo. But the same point applies to other examples where neither style promotes more code reuse than the other.
1 comments

The example you gave is obviously superior for the reason you mention, but what about just one where you are mutating the objects in the given list? Isn't the for loop and an if a lot clearer than names.toStream().if(something).then().mutate(thing)?
Sure, I think these things have to be evaluated on a case-by-case basis. Insisting on everything being written in a functional style seems a bit cargo-culty to me.