Table of Contents
Fetching ...

The Impact of Mutability on Cyclomatic Complexity in Java

Marat Bagaev, Alisa Khabibrakhmanova, Georgy Sabaev, Yegor Bugayenko

TL;DR

This work analysed 862,446 Java files from 1,000 open-GitHub repositories and demonstrated that immutable objects are almost three times less complex than mutable ones.

Abstract

In Java, some object attributes are mutable, while others are immutable (with the "final" modifier attached to them). Objects that have at least one mutable attribute may be referred to as "mutable" objects. We suspect that mutable objects have higher McCabe's Cyclomatic Complexity (CC) than immutable ones. To validate this intuition, we analysed 862,446 Java files from 1,000 open-GitHub repositories. Our results demonstrated that immutable objects are almost three times less complex than mutable ones. It can be therefore assumed that using more immutable classes could reduce the overall complexity and maintainability of the code base.

The Impact of Mutability on Cyclomatic Complexity in Java

TL;DR

This work analysed 862,446 Java files from 1,000 open-GitHub repositories and demonstrated that immutable objects are almost three times less complex than mutable ones.

Abstract

In Java, some object attributes are mutable, while others are immutable (with the "final" modifier attached to them). Objects that have at least one mutable attribute may be referred to as "mutable" objects. We suspect that mutable objects have higher McCabe's Cyclomatic Complexity (CC) than immutable ones. To validate this intuition, we analysed 862,446 Java files from 1,000 open-GitHub repositories. Our results demonstrated that immutable objects are almost three times less complex than mutable ones. It can be therefore assumed that using more immutable classes could reduce the overall complexity and maintainability of the code base.

Paper Structure

This paper contains 9 sections, 1 equation, 3 figures, 2 tables.

Figures (3)

  • Figure 1: A final field can still conain mutable data.
  • Figure 2: A final field can be inherited from the base class.
  • Figure 3: Even a properly immutable field can be modified through reflection.