chapter four

4 Writing Lean code

 

This chapter covers

  • Clarifying intent before implementation
  • Constraining solutions to prevent overproduction
  • Evaluating code based on removability, not cleverness
  • Recognizing hidden costs before they compound
  • Practicing judgment through deliberate reduction

You've probably been here: you spend three days building a feature, only to realize on day four that you misunderstood the requirement. Or you ask an AI to "add user authentication" and get back 800 lines of code with JWT refresh tokens, role-based permissions, and password complexity validators you never asked for. Or you inherit a module so tangled with dependencies that fixing a small bug means risking three other systems.

This chapter is about preventing that waste before you write the code. Writing Lean code is about writing code that's easy to understand, change, or delete when you don't need it anymore. In a world where AI can generate thousands of lines in seconds, knowing what not to build matters more than ever. The focus here is not on tools, frameworks, or clever techniques. It’s on developing judgment. You’ll practice making intent explicit before implementation begins, constraining solutions so they cannot quietly grow beyond their purpose, and evaluating code based on whether it earns its place in the system. The emphasis is on decisions you can apply immediately: how you frame work, accept or reject generated code, and recognize cost long before it shows up as a defect.

4.1 From code to spec: The evolution of defining intent

4.1.1 The waterfall era: Code is truth

4.1.2 Evolving to shift the source of truth

4.1.3 The AI era: Specs become explicit

4.1.4 Spec first: Define before you build

4.2 Design for deletion

4.2.1 Making code deletable

4.2.2 Designing for intervention: Enabling the software Andon

4.3 Managing dependencies and their hidden costs

4.3.1 The value of dependencies

4.3.2 Surface area

4.3.3 AI as a dependency and dependency generator

4.4 Standard work for coding

4.4.1 To spec or not?

4.4.2 Writing code

4.4.3 The code review

4.5 Exercise: From vibe coding to Lean coding

4.5.1 Start with vibe coding

4.5.2 Write the spec

4.5.3 Compare and contrast

4.5.4 Delete everything not in the spec

4.5.5 Reflect

4.6 Summary