Course contentsShow
← Software Engineering
Lesson 331 of 1,93310. RefactoringFree lesson

The Two Hats of Development

Separating refactoring from feature development: switching between adding functionality and improving structure, never doing both simultaneously.

The Two Hats of Development

What you'll learn: How to mentally separate adding new features from improving existing code—and why you should never do both at once.


When working on software, you're always wearing one of two hats: the feature hat or the refactoring hat. Understanding this distinction is essential for disciplined, effective development.

The Feature Hat

When you wear your feature hat, you're adding new functionality to the system. You might be writing new classes, adding methods, or implementing user-requested behavior. Your goal is to make the software do something it couldn't do before. During this time, you should resist the urge to "fix up" existing code—even if you spot opportunities for improvement.

The Refactoring Hat

When you wear your refactoring hat, you're improving the internal structure of existing code without changing its behavior. You extract methods, rename variables, eliminate duplication, or apply design patterns. You're making the code cleaner, but the software does exactly what it did before.

Why Never Both?

Attempting to add features while restructuring code is like trying to renovate your kitchen while cooking dinner. You'll lose track of what changes caused which effects. Did that bug appear because of your new feature or because you renamed something? Are your tests failing because the behavior changed (intentional) or because you broke something during refactoring (unintentional)?

Switching Hats Deliberately

Professional developers switch between hats consciously. You might add a feature (feature hat), commit your work, then immediately refactor to clean up what you just wrote (refactoring hat), then commit again. Each commit has a clear purpose.

Key Takeaway: Development requires two distinct modes—adding functionality and improving structure. Keep them separate, switch between them deliberately, and never mix them in a single change.