# Quantifying and Explaining Immutability in Scala

**Authors:** Philipp Haller, Ludvig Axelsson

arXiv: 1704.03095 · 2017-04-12

## TL;DR

This paper presents an empirical study on how immutability is used and understood in real-world Scala code, revealing common reasons for mutability and highlighting the lack of built-in immutability support in Scala's type system.

## Contribution

It provides the first comprehensive analysis of immutability practices in Scala, including explanations for mutable types and insights into how immutability is applied in practice.

## Key findings

- Immutable types are often mutable due to specific design reasons.
- Most common reasons for mutability include performance and flexibility.
- Statistics show prevalent patterns and challenges in achieving immutability in Scala.

## Abstract

Functional programming typically emphasizes programming with first-class functions and immutable data. Immutable data types enable fault tolerance in distributed systems, and ensure process isolation in message-passing concurrency, among other applications. However, beyond the distinction between reassignable and non-reassignable fields, Scala's type system does not have a built-in notion of immutability for type definitions. As a result, immutability is "by-convention" in Scala, and statistics about the use of immutability in real-world Scala code are non-existent.   This paper reports on the results of an empirical study on the use of immutability in several medium-to-large Scala open-source code bases, including Scala's standard library and the Akka actor framework. The study investigates both shallow and deep immutability, two widely-used forms of immutability in Scala. Perhaps most interestingly, for type definitions determined to be mutable, explanations are provided for why neither the shallow nor the deep immutability property holds; in turn, these explanations are aggregated into statistics in order to determine the most common reasons for why type definitions are mutable rather than immutable.

## Full text

_Full body text omitted from this summary view._ Fetch the complete paper as Markdown: https://tomesphere.com/paper/1704.03095/full.md

## Figures

4 figures with captions in the complete paper: https://tomesphere.com/paper/1704.03095/full.md

## References

12 references — full list in the complete paper: https://tomesphere.com/paper/1704.03095/full.md

---
Source: https://tomesphere.com/paper/1704.03095