1.

What Is Immutable Good For?

Answer»

Immutable data, once initialized, is never changed. This has many uses:

  • Access to immutable data need not be synchronized when multiple threads read it.
  • Data races, tearing, sequential consistency, and cache consistency are all non-issues when working with immutable data.
  • Pure functions can only accept immutable parameters.
  • When doing a DEEP copy of a data structure, the immutable portions need not be copied.
  • Invariance allows a large chunk of data to be treated as a VALUE type even if it is passed around by reference (strings are the most common CASE of this).
  • Immutable type provides more self-documenting information to the programmer.
  • Immutable data can be placed in HARDWARE protected read-only MEMORY, or even in ROMs.
  • If immutable data does change, it is a sure sign of a memory corruption bug, and it is possible to automatically check for such data integrity.
  • Immutable types provide for many program optimization opportunities.

const acts as a bridge between the mutable and immutable worlds, so a single function can be used to accept both types of arguments.

Immutable data, once initialized, is never changed. This has many uses:

const acts as a bridge between the mutable and immutable worlds, so a single function can be used to accept both types of arguments.



Discussion

No Comment Found