Refactoring Print

  • softwareengineering, software, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Improving structure without changing behaviour.

WHAT IT IS

Changing the structure of code while preserving what it does.

WHY IT MATTERS

Without it, code decays with every change, until change becomes impractical.

WHAT IT REQUIRES

Tests.

WHY

Without them you cannot know behaviour was preserved.

WHAT TO DO IF THERE ARE NO TESTS

Write them for the area you are changing, first.

WHAT COMMON REFACTORINGS ARE

Extracting a function or a variable Renaming Inlining something that adds nothing Replacing a conditional chain with polymorphism Moving something to where it belongs Introducing a parameter object

WHEN TO REFACTOR

Continuously, in small steps, as part of normal work.

WHY NOT AS A PROJECT

Large refactoring projects are difficult to justify, are cancelled, and produce long-lived branches.

WHAT THE RULE IS

Leave the code better than you found it, slightly, each time.

WHAT TO AVOID

Refactoring and changing behaviour in the same commit.

WHY

The real change becomes invisible among structural changes.

WHAT TO RUN AFTER EVERY STEP

The tests.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot