Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling in functional programming

I heard that programs written in a functional language tend to scale better. Is this true and if so then what are the differences from non functional languages that cause this?

like image 295
Jim Jeffries Avatar asked Feb 28 '26 04:02

Jim Jeffries


1 Answers

Whoever you heard this from was most likely referring to the fact that "Disallowing side effects provides for referential transparency, which makes it easier to verify, optimize, and parallelize programs, and easier to write automated tools to perform those tasks."

In other words, functional programs tend to not have side effects (modifying global state) so running many instances of a functional program in parallel should produce the same output. For example, consider the difference between

int a;
void increment_a() {
    a++;
}

and

int increment(int a) {
    return a+1;
}

The second has no side-effects and can be run in parallel, provided you structure your code so that you provide all the necessary inputs.

like image 197
raylu Avatar answered Mar 04 '26 07:03

raylu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!