|
|
|
|
|
by BenoitEssiambre
3670 days ago
|
|
I rarely use FP but I certainly see it's appeal for certain things. I think the concept of immutability confuses people bit. It really clicked for me when I stopped thinking of it in terms of things not being able to change and instead in terms of every version of things having different names. Functional programming from that perspective is like version control for your variables. It makes explicit, not only which variable you are accessing but which version of it. The reason it seems like you need to copy a variable each time you modify is just to give each particular mutation a different name. Note that the compiler can optimize things. It doesn't need to keep every version in memory. If it sees that you are not going to reference a particular mutation, it might just physically overwrite it with the next mutation so that in the background "var a=i, var b=a+j", might run as something like "var b = i; b+=j"; |
|