Hacker News new | ask | show | jobs
by hnruss 2342 days ago
Functional Programming fundamentally changed the way that I solve problems. It also changed my expectations for how code should be designed.

The concepts that influenced me the most were immutability and the power of mapping+filtering. Whenever I read a for/while loop now, I’ll attempt to convert it to the FP equivalent in my head so that I can understand it better.

2 comments

I’d do the complete opposite. Instead of using mapping and filters I’d prefer for loops.
map and filter are not concepts of FP - they are just syntactic sugar around for loops. fully evident if you check any native source code. many languages (such as go which I currently use) do not even have these functions but can apply FP. this is by design of simplicity and visibility: it does not get much easier to read than a simple for loop and know the exact iterations count at runtime.
One of the key principles of functional programming is, well, functions. A for loop isn't a function and isn't composable, map and filter are.
They are not equivalent - for loop prescribes the ordering of processing, but map and filter can work in any order. They are often associated with FP because to define these operators, you need to be able to pass functions as parameter to other functions, which is a thing that surprisingly many languages struggle with.
That's like saying SQL is just syntactic sugar around loops for databases. Might be true but it misses the whole point of declarative programming.