Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My confusion here is it always seemed liked a simple mapping to take = to mean "make x equal to x+1" rather than "x is already equal to x+1".

It is declaring a relationship, between the previous value and the current. One way or another, youre defining transformations.

I mean even in the sum example, you see the statement "N is n-1" which is the exact same thing as x = x+1 with = swapped for "is"



That's why I like the

    x := x + 1
syntax better, or the

    let x = 2;
syntax


> even in the sum example, you see the statement "N is n-1"

That wasn't actually what the example said. It said N1 = N - 1, and continued using the N1 value somewhere else. In that example, no actual mutation occured.


Oh my weary eyes, my bad


It's N1 is N - 1, not N is N-1


It is difficult to understand the full beauty (or horror, depending on your pov) of functional programming with such a simple example. But as you scale up in complexity, it can be someone’s full time job to make sure the model is accurately translated to the computer’s memory. With a pure language, the compiler is responsible for maintaining the mapping to memory, so you (mostly) just focus on the symbolic relationships of your model. This can be extremely freeing once you train yourself to think in functional terms. Of course, there is a performance cost, but this can be managed and in cases where people turn to functional programming reliability and correctness outweigh the cost.


Pure languages still use stack to store mutating state. In a single-threaded programs this is almost non-observable except for occasional stack overflow crashes. But with multiple threads and message passing one can emulate arbitrary state mutation just by using messages and stack.

Then I have found the code that is a heavy user of closures is harder to understand even if it is single-threaded and closures can pass arbitrary state even if the state is immutable.

What I have found useful is persistent data structures. Those really simplify modelling. But then those can be used in imperative languages as well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: