liveBook · Manning

Safe zone

As explained in Grokking Simplicity

A system region in which code is trusted to preserve the intended data-safety and immutability guarantees.

A safe zone is a region where code is trusted to preserve data-safety and immutability guarantees. Copy-on-write defines the zone; defensive copying protects its borders. section 7.8

Keep the boundary clear with two complementary disciplines:

  • Inside the safe zone, use copy-on-write: make a shallow copy, modify the copy, and return it. section 7.8
  • When data enters or leaves the safe zone, use defensive copying: make a deep copy at each border. section 7.8
  • Treat copy-on-write as relatively cheap and defensive copying as relatively expensive, reflecting shallow versus deep copies. section 7.8
  • Use defensive copying when exchanging data with untrusted code, including existing code and libraries. section 7.11

Choosing the discipline

Modifying data you control calls for copy-on-write; exchanging data with untrusted code calls for defensive copying. Neither discipline is a complete immutability solution alone. section 7.8 section 7.11

How Grokking Simplicity covers it

How deep it goes
Defines internal and boundary rules, copy types, costs, and limitations without detailing implementation mechanics.
Examples
Contrasts modifying controlled data with exchanging data across an untrusted-code boundary.
What it assumes
Assumes familiarity with immutable data, shallow copies, deep copies, and trusted or untrusted code.
What you can do after
Apply copy-on-write internally and defensive copying at safe-zone boundaries.
How it connects
Connects copy-on-write, defensive copying, immutability, and untrusted code.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Simplicity. The section links point to the parts of the book it draws on.