Enumerating the benefits of being immutable

After our discussion, we now know that an immutable object is an essential part of the functional programming. The following are the benefits we can get from the immutable object:

  • We won't deal with the side effect. It's because we have ensured that no outside state is modified. We also create a new object every time we intend to change the value inside the object.
  • There is no invalid object's state. It's because we will always be in an inconsistent state. If we forget to invoke a particular method, we will definitely get the correct state since there is no connection between methods.
  • It will be thread-safe since we can run many methods together with no need to lock the first method that is run ...

Get Learning C++ Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.