Tag: immutability

Python Immutability for Collection-Typed Attributes

I came across a situation recently where I wanted to preserve the immutability of lists of data that were being returned from a Python class. I held an implicit assumption that nothing in the code would change the content of the lists. But nothing enforced this assumption in the code, and the logic in the

Java Immutability for Collection-Typed Properties

Immutability is an important tool for writing more reliable code. Several of the core classes in Java are immutable (String, Integer, etc). But the principle of immutability can also be applied to specific areas of application code to improve the reliability and predictability there. An immutable object can be trusted to carry unchanging data between

Counting Words in Java with a Mutable Counter

One of the hallmark features of the Java programming language is the immutability of basic “wrapper” data types like String and Integer. Immutable types are inherently concurrency safe and have other properties that can improve code quality, but sometimes immutable types can be costly because of their inherent unchangeability. Immutable types are safe for concurrent