Most code I come across is in the red zone, exactly depicting why you want immutable constructs. Immutable constructs will never end-up in the red zone.
Image: [WayBack] Wayback Machine.
The red zone is just one quadrant on the mutability/shareability diagram and getting outside that red zone quadrant is key.
With processor cores now becoming ubiquitous: you cannot get outside of the “Shard” half, so you have to get outside of the “Mutable” half.
Explaining the why and how, is part of a few presentations that Kevlin Henney gave:
- [WayBack] Refactoring to Immutability
- [WayBack] Thinking Outside the Synchronisation Quadrant
- [WayBack] Immutability FTW! (there is no YouTube video of it)
- [WayBack] Functional C++
- [WayBack] Software Is Details
Related YouTube videos are below.
–jeroen