Course contentsShow
← Software Engineering
Lesson 500 of 1,93315. Test-Driven DevelopmentFree lesson

The Transformation Priority Premise

Follow a preferred order of code transformations from simpler to more complex during the TDD cycle.

The Transformation Priority Premise

You'll learn: How to choose the simplest code changes that make your TDD tests pass, following a natural progression from basic to complex transformations.

What Is This About?

When you're in the TDD cycle making a test pass (the "Green" step), you often have multiple ways to write the code. The Transformation Priority Premise suggests there's a preferred order for these code changes—moving from simpler transformations to more complex ones. This keeps your implementation naturally clean and helps you avoid over-engineering.

Think of it like learning to cook: you start with boiling water before attempting soufflés. Each skill builds on the previous one, and skipping steps leads to messier results.

The Priority Order

Uncle Bob Martin proposed this ranked list of transformations (simpler → more complex):

  1. Null → return null or nothing
  2. Null to Constant → return a literal value
  3. Constant to Variable → replace the literal with a variable
  4. Unconditional to Conditional → add an if statement
  5. Scalar to Array → change from single value to collection
  6. Array to Container → use more sophisticated data structures
  7. Statement to Recursion → solve with recursive calls
  8. If to While → introduce loops
  9. Expression to Function → extract into separate functions

Why This Matters

By preferring simpler transformations, you avoid jumping straight to complex solutions. If you can make the test pass by returning a constant, do that first. Let additional tests drive you toward variables, then conditionals, then loops—naturally.

This approach keeps each step manageable and prevents the "clever code" trap where you prematurely generalize.

Key Takeaway: Transform your code using the simplest change that makes the test pass; let new tests push you toward more complex transformations only when needed.