|
|
|
|
|
by substation13
1546 days ago
|
|
A related advantage is expression-orientated code. In ML languages, code forms a beautiful tree structure where you can see the binding definition of each binding by looking down and right. let x =
something
really
big
and
complicated
whereas in a language built around statements it will be scattered all over: let x = null;
x = something();
x = somethingElse(x);
x = anotherThing(x);
In the first case the definition of x is in one indented block; you can read it and move on. |
|
something(x, result);
somethingElse(result, result2);
anotherThing(result2, result3);
with the occasional surprise mutation when you just have to do
something(x)
and x contains the result.
I also got caught recently with MomentJS with that one when doing mydate.add and discovering it also mutated the original instead of just returning the result.
I'm a very average programmer and far from a FP purist (I mostly use JS and Rails) and I'm surprised how much I now use some FP principles and how it feels very natural to me.