Programming Search⌘K

Moving features

The refactorings of chapter 8 that move functions, fields and statements to a better place.

Techniques

  • Move field

    Move a field to the record or class that it belongs with, after you encapsulate it, so that data that changes together lives together.

    core
  • Move function

    Move a function to the class or module whose data it uses most, and leave a delegating call or nothing behind; called Move Method in the first edition of Refactoring.

    core
  • Move statements into function

    When the same statements run each time a function is called, move them into the function, so that callers cannot forget them; the inverse of Move Statements to Callers.

    core
  • Move statements to callers

    When some callers of a function need part of its behavior to be different, move that part out of the function into each caller; the inverse of Move Statements into Function.

    core
  • Remove dead code

    Delete code that no longer runs or whose results nobody uses, after you check that nothing reaches it; version control keeps the old version if you ever need it.

    core
  • Replace inline code with function call

    Replace inline code that does what an existing function already does with a call to that function, from the project or from a library, so that the code says what it does by name.

    core
  • Replace loop with pipeline

    Replace a loop that filters, transforms and collects items with a collection pipeline of operations such as filter, map and reduce; each language has its own form.

    core
  • Slide statements

    Move statements up or down so that code that works on the same thing is together, after checking that the move does not change what the code does; a usual first step before Extract Function.

    core
  • Split loop

    Split a loop that computes two things into two loops that compute one each, so that each can be understood, extracted and changed on its own; measure before you worry about the cost.

    core