Ask HN: Advantages of immutable variables besides concurrency
Some languages, notably erlang has immutable variables. Are there any advantages to this besides
making concurrent programming easier ?
"Composability means that you can put two bits of code together and important correctness properties will be preserved automatically. This does not mean, of course, that the composition is automatically correct in a wider sense, but it does mean that you don’t introduce new bugs merely by sticking two things together." (http://paulspontifications.blogspot.com/2007/09/composabilit...)
Also, some data structures are simply incorrect when the data is mutable. A hash table with mutable keys comes to mind. Why? Once you insert the key-value pair, and mutate the key, you may not be able to find that key anymore.
It also makes sharing common parts between different data structures easier.