Posts

Showing posts from February, 2026

Different Types of Immutability

Different Types of Immutability  Here are the specific types of immutability in programming: Strict/True Immutability: The object or value cannot be changed at all after it is initialized. Examples include constants, strings, integers, and tuples in many languages. Shallow Immutability: Only the immediate fields or references of an object are immutable, but the objects they reference can still be changed. A "read-only" field might point to a mutable object. Deep/Strong Immutability: The entire object graph is immutable. All fields, and all objects referenced by those fields, are also immutable. Copy-on-Write (Persistent Data Structures): While the data structure appears immutable to the user, any change triggers the creation of a new, updated copy. The original remains unchanged. Compile-time Constants (Write-once): Fields that are assigned a value at compile-time and cannot be changed during runtime, such as const in C# or final in Java.

F# and Immutability

F# and Immutability In F#, everything is immutable except arrays.  In F#, you get immutability "for free" in most cases.

Immutability vs. ReadOnly

 Immutability vs. ReadOnly   The key difference is that readonly restricts reassignment of a reference/variable, while immutable guarantees that the contents or state of an object cannot be changed after creation.   Example (C#): A readonly List<T> cannot be set to a new List<T> instance, but you can still call methods like Add() or Remove() on the existing list.

Immutability and C#

Immutability and C# C# has System.Collections.Generic.Immutable collection that was introduced in .NET Framework 4.5 (around 2012–2013). I went back and revisited Jinaga by my friend, Michael Perry.   https://github.com/jinaga/jinaga.net I investigated the code generators for immutability types by A. Arnott and Nikolay Pianikov: https://github.com/AArnott/ImmutableObjectGraph https://github.com/DevTeam/Immutype

Immutability and Security

Immutability and Security   I have been thinking about immutability and security.  Was thinking about how immutables have better security overall (since cannot modify), but not entire security since security is also visibility.