Refactoring (Reichenbach)

Content

  • Why do we change program structure?
  • What are Bad Smells?
  • What is Refactoring?
  • How and when is refactoring useful?
  • What are some common program structures that we might refactor into?

Videos and Quiz

Session structure

Learning resources

 

Grading criteria

To pass this module, you will perform refactorings in a code repository that you are working on for one of the other modules. Each refactoring must be committed to the repository as a single commit.

You can choose a combination of simple and complex refactorings, but the total refactoring score must be at least 16 points. A simple refactoring is worth one point and a complex one is worth three points. See the lists below for acceptable refactorings. You must include at least two complex refactorings.

Keep in mind:

  • Changed 15 March: You should submit a list of commits and diffs on canvas. The reason for that is that requesting access to that many git repositories is not practical (Noric needs to create an account on every gitlab instance students use).
  • Noric (your grader) will review your commits.
  • Each refactoring must be submitted in a single commit.
  • The commit must name the refactoring (try to follow the naming scheme of the refactoring catalogues as much as possible).
  • You must submit a list of the commit identifiers and diffs for the refactoring commits to Canvas by Friday the 2nd of April.

How do you submit?

If your commits messages contain the word "Refactoring", you can submit the result of the command git log -p --grep "Refactoring" (-p prints diffs along with the commit information, --grep filters the commits whose message matches a string). Otherwise, you can print the diffs for specific commits with the command git show -p <COMMIT1> <COMMIT2> ... for the commits you want to include in your submission. Redirecting the output of this command to a file should give you what we want, you can then copy paste this text as your submission on canvas.

Refactorings

For other refactorings than the ones listed below, check with Noric whether they count as Complex or Simple.  We will update this list as new decisions are made.

Complex refactorings (3 points each):

Simple refactorings (1 point each):

Non-refactorings (0 points):

  • Functional changes.
    • Bug fixes. 
    • Adding new features/options.
  • File/directory renaming.
  • Changes to build system, build script, toolchain.
  • Changes to data only.
  • Renaming output files; only affecting string literals in the code.
  • A commit that only adds code is usually not a refactoring (unless it is an assertion or the code replaces some implicit behaviour)

For more information about these refactorings, refer to e.g. Catalog of Refactorings Links to an external site..

 

Alternative project

If you are already a master refactorer and bored by this project, you can opt to re-implement and evaluate the system from Does automated refactoring obviate systematic editing? Links to an external site. (ICSE'15), simplified as needed to fit into a one-month timeframe, or propose a refactoring-related research or engineering project to the instructor (e.g., implementing and evaluating a language server Links to an external site. with refactoring support for a language that lacks such a tool).