Refactoring journey

Practice refactoring tips to improve your day-to-day efficiency

Objectives

  • Practice refactoring tips to improve your day-to-day efficiency

  • Use your IDE features

Before we start

  • Clone the repository here

  • Make sure you can run the tests

Connection

Refactoring, you said refactoring ?

Names of Refactorings :

  • Write down names of refactorings you already know

  • Write up names on a whiteboard or flipchart

Remind them some they use probably : Rename Variable and Extract Interface.

Concepts

Several ways to write code

What is refactoring ?

Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.

Refactoring (verb): to restructure software by applying a series of refactorings without changing its observable behavior. - Martin Fowler

Refactoring is a systematic process of improving code without creating new functionality that can transform a mess into clean code and simple design.

The main purpose of refactoring is to fight technical debt

When to refactor ?

When adding a feature

  • If you must deal with someone else’s dirty code, try to refactor it first

    • Clean code is much easier to grasp

  • Refactoring makes it easier to add new features

    • Easier to make changes in clean code

Rule of Three (duplication)

  • You can copy and paste the code once

  • BUT when the same code is replicated 3 times, it should be extracted into a new procedure

When fixing a bug

  • Clean your code and the errors will practically discover themselves.

During a code review

  • Code review may be the last chance to tidy up the code before it becomes available to the public

  • Best to perform reviews in a pair with an author : you could fix simple problems quickly

When paying your debt

  • Dev teams can create technical debt consciously at one time and book some time later to tackle it

How to ?

There are two cases when tests can break down after refactoring :

  • You made an error during refactoring

    • Go ahead and fix the error

  • Your tests were too low-level (for example, you were testing private methods of classes)

    • In this case : the tests are to blame

    • Either refactor the tests themselves or write an entirely new set of higher-level tests

Concrete Practice

Follow the journey step by step as explained in my website :

Enjoy the Journey

Conclusion

Learning feedback

  • Each participant add his/her name on the quadrant

  • Please explain why you are there

Last updated