7 Staying immutable with untrusted code
In this chapter
- Make defensive copies to protect your code from legacy code and other code you don’t trust.
- Compare deep copies to shallow copies.
- Choose when to use defensive copies versus copy-on-write.
We’ve learned how to maintain immutability in our own code using copy-on-write. But we often have to interact with code that doesn’t use the copy-on-write discipline. There are libraries and existing code that we know treat data as mutable. How can you pass your immutable data to it? In this chapter, we learn a practice for maintaining immutability when interacting with code that might change your data. ...
Get Grokking Simplicity 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.