Re:Why study functional programming? (2012)
by freedomben on Tuesday August 02, 2022 @02:22PM
(#32322433)
Immutability can be fast or slow depending on the implementation. There are tons of copy-on-write implementations that blaze past mutable implementations. When the compiler knows that a particular variable/piece of data will never be changed, it opens up a ton of optimizations that can be used to make it fast. With mutable memory it's on the developer to optimize, rather than the compiler. Most of the time, the latter is better at it.
[ Parent
| on HN ]
With infinite memory and "no cost memory allocation" you'll be likely correct, but in real world production loads you'll hit those limits quickly and then the immutability is likely getting in the way. Imagine just keeping a large (possibly compressed) bitmap (TBs in memory) to keep track of subscribers in your queue which is what many distributed queues use - how would you do it in immutable fashion? Copy the whole bitmap on each small change? There are simply many problems where immutability is the wrong answer if you want anything resembling performance.
Re:Why study functional programming? (2012)
by freedomben on Tuesday August 02, 2022 @03:07PM
(#32322955)
Absolutely, that would be one of the cases where "most of the time" is not "this time." Although for most developers/applications, I would imagine keeping TBs of bitmap in memory isn't a common task. Fetching some rows from the DB and transforming them into some sort of HTML or JSON probably is
Re:Why study functional programming? (2012)
by kephasp on Tuesday August 02, 2022 @07:27PM
(#32325625)
Do you have any examples? Tons of system use immutability with extremely high throughputs, most notably WhatsApp.
I don't need infinite memory to make a finite number of modifications to an optimized persistent data structure.
Re:Why study functional programming? (2012)
by guelo on Tuesday August 02, 2022 @02:39PM
(#32322661)
The problem is that developer has no idea if the implementation is going to be performant for their use case. The mutable compilers normally have less magic and thus are easier for the developer to understand and optimize. FP is really just a higher level language, that's why they don't teach algorithms classes using FP languages.