The Economic Benefit of Refactoring(martinfowler.com)
247 points by javaeeeee 20 hours ago | 107 comments
tl;dr: A developer refactored a 17,155-line Rust data access layer (in an agent-generated 150K LoC app) through 15 disciplined steps, running an experiment where a fresh sub-agent repeated the same feature-addition task after each step to measure token cost. Input tokens for the representative change dropped 83% (from ~160K to ~27K), primarily because the agent could identify and read smaller relevant subsets of code once files were properly decomposed. Output tokens barely changed, and Claude itself proved poor at both identifying and mechanically executing refactorings without human guidance.
HN Discussion:
  • AI needs are reinventing long-known best practices humans already ignored
  • ~Refactoring's real value is human comprehension, not just token savings
  • LLMs benefit from clean code but can't produce it without human guidance
  • Appreciation for grounded, quantitative analysis over vague AI commentary
  • Good abstractions and compact context improve reasoning and correctness beyond tokens