liveBook · Manning

Chapter 4: Writing Lean code

What you will learn in chapter 4 of Build High Value Software Systems

The introduction frames Lean coding as preventing unnecessary work by deciding what code is needed and keeping it easy to understand, change, or delete.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction frames Lean coding as preventing unnecessary work by deciding what code is needed and keeping it easy to understand, change, or delete.

Key terms: Lean code, deliberate reduction, intent, overproduction, dependencies, judgment

4.1 From code to spec: The evolution of defining intent

This section explains how a team’s chosen source of truth shapes its work and waste, and why explicit specifications can define intent before code is generated.

Key terms: source of truth, authoritative, waste profile, TDD, BDD, SDD, waste, explicit specifications, specification, AI generation

4.1.1 The waterfall era: Code is truth

The section uses the waterfall era to show why code became the only reliable account of a system and why building everything—or documenting everything—up front created Lean waste.

Key terms: code was the truth, requirements, design, testing, overproduction, delayed customer feedback, rework, Documentation Driven Development (DDD), waiting, inventory

4.1.2 Evolving to shift the source of truth

The section compares ways to define correctness before implementation and uses a Lean lens to judge when their benefits justify their overhead.

Key terms: Test-Driven Development (TDD), pull signal, done, technical value, user value, business value alignment, regressions, Behavior Driven Development (BDD), Gherkin, translation overhead

4.1.3 The AI era: Specs become explicit

AI can produce plausible code for the wrong problem very quickly, making it important to define the intended contract before implementation begins.

Key terms: AI, intent, plausible solutions, Spec Driven Development (SDD), TDD, contract, done

4.1.4 Spec first: Define before you build

Shows how a spec written before coding constrains AI-generated work, protects value, and makes mismatches between intent and implementation visible early.

Key terms: spec, pull signal, overproduction, server-side streaming, bounded batches, cursor, user privacy, source of truth, quality gate, Andon moment

4.2 Design for deletion

The section treats code as inventory with ongoing costs and argues for making it easy to remove, especially as AI makes code faster to generate.

Key terms: inventory, carrying costs, obsolescence, design for deletion, value, AI, cost of having code, deletion

4.2.1 Making code deletable

This section shows how coupling and expected lifespan should shape code so it can be removed safely without creating unnecessary structure.

Key terms: coupling, deletability, design input, speed and reversibility, change and understanding, proportional structure, longevity, design for deletion, design for endurance

4.2.2 Designing for intervention: Enabling the software Andon

The section explains how making behavior safe to disable or remove turns an Andon signal into a practical way to protect software quality.

Key terms: Andon signal, pull the cord, designing for deletion, Andon moment, Gemba, Kaizen, off switch, deletion debt, ease of deletion, foundational

4.3 Managing dependencies and their hidden costs

The section weighs the immediate benefits of reusing libraries against the lifetime costs of accumulating dependencies.

Key terms: dependencies, well-tested libraries, domain-specific value, inventory, transitive dependencies, lifetime cost, AI-assisted development

4.3.1 The value of dependencies

This section evaluates dependencies through user, business, and technical value while accounting for inventory and maintenance costs.

Key terms: user value, inventory, dependencies, business value, initial velocity gain, ongoing maintenance cost, foundational dependencies, technical value, surface area

4.3.2 Surface area

This section explains how dependencies expand a system’s exposure and how to weigh that lasting cost against the value of using a library.

Key terms: surface area, attack surface, transitive dependencies, CVE, auditable code, cryptography, parsing, protocols

4.3.3 AI as a dependency

This section treats AI as a development dependency whose hidden costs grow when generated code is poorly understood or lacks shared standards.

Key terms: dependency, User Value, Business Value, Technical Value, cognitive attack surface, cognitive debt, dependency cascade, transitive assumptions, non-deterministic, probabilistic generation

4.3.4 AI as a dependency generator

Shows how an AI-suggested library can spread into architectural lock-in, and how standard work can filter dependency choices before they create waste.

Key terms: external dependency, styled-components, architectural lock-in, stylistic dependency, standard work, local optimization, global waste, value check, surface area check, reversibility check

4.4 Standard work for coding

This section defines standard work for coding and shows how it reduces friction and creates consistency.

Key terms: standard work, TDD, SDD, dependencies

4.4.1 To spec or not?

This section explains when to write a spec before coding and how to make it precise enough to prevent assumption-driven variation.

Key terms: spec, valid input, valid output, never statements, dependencies, existing patterns, clear boundary, functionally identical implementations, assumptions, variation

4.4.2 Writing code

This section explains how to use a team's coding standards to make consistent choices while documenting justified exceptions.

Key terms: standard work doc, dependency cascade problem, standard, deviation, conscious trade-off, rationale

4.4.3 The code review

This section shows how Lean code review uses documented criteria to stop waste before merge and uses recurring review findings to improve team standards.

Key terms: spec, standard work, merge blockers, overproduction, coupling, deletable, Gemba, Kaizen, standards, checklist

4.5 Exercise: From vibe coding to Lean coding

Introduces an exercise comparing AI-generated code from a casual prompt with code constrained to the actual need.

4.5.1 Start with vibe coding

This exercise creates an unconstrained AI-generated webhook handler so the reader can observe how a plausible solution grows beyond the request.

Key terms: vibe coding, dependencies, imports, event processing architecture, waste, code smell

4.5.2 Write the spec

This section shows how to write a minimal behavioral spec independently of AI-generated code, while making genuine constraints explicit.

Key terms: spec, Input, Behavior, Never, Errors, architecture, implementation details, constraints, Dependencies

4.5.3 Compare and contrast

This exercise compares AI-generated webhook code with spec-based code to identify unnecessary features, hidden assumptions, premature optimizations, and dependencies before changing anything.

Key terms: spec-based code, overproduction, TIMWOODS, hidden assumptions, premature optimization, dependency count, packages, dependency injection, repository pattern

4.5.4 Delete everything not in the spec

This exercise uses the spec to strip unnecessary code from a payment webhook handler, then updates the spec with what the deletion revealed before generating code again.

Key terms: spec, waste, queues, refined spec, Constraints, Never:

4.5.5 Reflect

This exercise uses a comparison of bloated and refined code to reveal waste, improve a spec, and identify where team standards need to be clearer.

Key terms: User Value, Business Value, Technical Value, casual prompt, bloated code, waste, spec, boundaries, deletion process, refined spec

4.6 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 3: AI as a partner and problem Chapter 5: Testing as waste prevention →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.