liveBook · Manning

Side effect

As explained in The Art of Code

A side effect is an observable change or interaction produced by a computation beyond returning its direct result.

A side effect is an observable change beyond a computation’s direct return value. Writing files, updating databases, sending network requests, changing global state, and printing logs all alter the surrounding world. section 6.1.1

Side effects make behavior harder to trust when they remain hidden:

  • Identical calls can produce different results when external factors or mutable state change. section 6.1.1
  • Hidden mutations complicate reasoning, debugging, and testing because a method signature may not reveal what it changes. section 6.1.1
  • Functional purity limits such effects by isolating behavior and expressing predictable transformations over data. section 6.0

Imperative steps versus a visible transformation

Imperative filtering creates a mutable result, loops through words, checks each condition, converts matches, and appends them. A functional pipeline makes the transformation itself visible: extract titles, sort them, then collect the result. section 6.1.1 section 6.0

List<String> result = new ArrayList<>();
for (String word : words) {
    if (word.length() > 3) {
        result.add(word.toUpperCase());
    }
}

Inspect the imperative example’s explicit mutation and control flow. section 6.1.1

List<String> titles = books.stream()
.map(Book::title)
.sorted()
.toList();

Inspect a concise pipeline that exposes data transformation without control-flow noise. section 6.0

How The Art of Code covers it

How deep it goes
Defines observable changes, lists consequences, and contrasts imperative mutation with functional transformations without examining runtime internals.
Examples
Uses file writes, database updates, network requests, global mutation, console logging, and Java filtering and stream pipelines.
What it assumes
Assumes familiarity with mutable data and imperative control flow while contrasting them with functional purity and immutability.
What you can do after
Diagnose/debug hidden behavior and recognize when functional transformations can make effects more predictable and testable.
How it connects
Ties side effects to imperative programming, mutable data, functional programming, pure functions, immutability, and testing.

Also explained in

Compare how 24 books explain side effect →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.