Skip to content

Instantly share code, notes, and snippets.

@rynmrtn
Created December 28, 2009 20:31
Show Gist options
  • Save rynmrtn/264917 to your computer and use it in GitHub Desktop.
Save rynmrtn/264917 to your computer and use it in GitHub Desktop.

Immutable vs. Mutable Objects

Advantages of Immutable

  • There is no way for multiple threads to concurrently mutate or access an immutable value as no thread can change an immutable object.
  • When passing a value into foreign code, one can be assured that an immutable value will not change.
  • There are fewer concerns - immutable objects cannot have complex states that change over time.

Disadvantages of Immutable

  • When an object is quite large, it is inefficient to update the full object graph. In some cases, it is best to do an in-place modification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment