Hacker News new | ask | show | jobs
by ionforce 4338 days ago
It is a guarantee to you that the data structure has not been tampered with by the time it reaches you.

    // pseudo code

    var fruitBasket = new FruitBasket('banana, 'apple)

    muckWithFruits(fruitBasket)
    suspiciousLogger(fruitBasket)
    weirdCallback(fruitBasket)

    // here
    assert(fruitBasket.length == 2)
By the time we reach "here", we know that none of the functions since the inception of fruit basket have tampered with it.

This may not be a big deal if you are disciplined about never modifying your source data, but this moves the guarantee from a soft one to a mechanical one.

And then there's all this typical stuff about functional programming blah blah... But that's the most practical example I can think of.

1 comments

If everything is immutable, it also makes it a lot easier to parallelize tasks, because you can easily deduce a dependency graph.