👨‍💻
Software Engineering
Tidy First?: A Personal Exercise in Empirical Software Design
Tidy First?: A Personal Exercise in Empirical Software Design
  • Tidy First?
  • Foreword
  • Preface
  • Part 1: Tidyings
    • 1: Guard Clauses
    • 2: Dead Code
    • 3: Normalize Symmetries
    • 4: New Interface, Old Implementation
    • 5: Reading Order
    • 6: Cohesion Order
    • 7: Move Declaration & Initialization Together
    • 8: Explaining Variables
    • 9: Explaining Constants
    • 10: Explicit Parameters
    • 11: Chunk Statements
    • 12: Extract Helper
    • 13: One Pile
    • 14: Explaining Comments
    • 15: Delete Redundant Comments
  • Part 2: Managing
    • Coming soon
  • Part 3: Theory
    • Coming soon
Powered by GitBook
On this page
  1. Part 1: Tidyings

8: Explaining Variables

Some expressions grow. Even if they start small, they grow, and grow.

Later on, we return and try to understand what is happening.

When you understand part of a big, hairy expression, extract the subexpression into a variable name that captures the intention.

This is often seen in graphics code:

return new Point(
    ...big long expression...
    ...another big long expression...
)

Before changing the expression, tidy it first:

x := ...big long expression...
y := ...another big long expression...
return new Point(x,y)

In this tidying we're taking the hard-won understanding and putting it back into the code. Changing the expressions is now easier. Next time, they'll be easier to read.

As always, separate the tidying commit from the behavior change commit

Previous7: Move Declaration & Initialization TogetherNext9: Explaining Constants

Last updated 9 days ago