Refactor

Introduction

One of the ways that we can improve our programming skills is through iteration. Though it is possible to plan a programming project by function or even by line before you even start to code, often times it is best to simply jump in and get started. Much like narrative writing, it is quite natural to view code as a series of rough drafts—with each new draft making incremental improvements on the version that preceded it. As the program that you are writing starts to take shape, decisions that you made at the beginning might not work as well with your current code as they did when you first started. As you write your program you may discover better ways to implement a particular segment of code. These types of realizations are a normal part of the coding process.

In programming, making incremental improvements to working code is often referred to as refactoring. Code is refactored to remove unnecessary syntax, make performance improvements, and improve reliability. Naturally, some bugs will be fixed during the refactor process, but solely removing bugs from a program is not in and of itself considered a refactor.

Since you will be developing your first real programs in this class, your knowledge of how to write code will grow quickly. As your skills improve, the way you write code in assignment 0 or 1 will likely be quite different from the way you write code in assignment 5 or the final project. Inevitably, you will start to identify aspects of your code that can be improved. When you do, we want to reward you by allowing you to complete an assignment refactor for credit.

How to Write a Refactor

You will have the opportunity to improve your code for up to three main assignments (A1-A5) by submitting a refactor. You can refactor any main assignment that you want, but no more than three. For this class we will define a refactor as a single or multi-step improvement to the functionality of your program. A refactor is not:

  • A bug fix

  • An assignment requirement or fix that you missed.

  • A new feature

To be considered complete, a refactor must make identifiable improvements to your code. You may fix bugs in your code, but these changes alone do not constitute sufficient work for a refactor.

A successful refactor will include:

  • A README file that clearly explains:

    • The code that you will be refactoring, and why.

    • The improvements you plan on making, and why.

  • Successful implementation of your planned improvement.

  • Successful function of the improvement.

If any of these requirements are not met, your refactor will not be accepted. If you would like a quick gut check on your refactor plan you are more than welcome to submit your README to the instructor for approval.

When to Write a Refactor

You don’t have to have a low grade to refactor. If you received full credit on your assignment, you can still submit a refactor. There is always room for improvement! Similarly, you do not have to wait for graded feedback on your assignment to work on a refactor. In fact, we prefer if you identify issues on your own rather than rely on our input to decide where to make improvements.

Refactors allow you to get a little bit extra out of your grade for this course. If by the end of the quarter you are .05 percent away from the next grade level, a solid set of refactors will get you there. So be aware, if you are just shy of the next grade level and you have not completed any refactors, then it’s probably not a good idea to ask for a grade bump. :)

When to Submit

All refactors must be submitted by the deadline specified on Canvas. Due dates have been weighted towards the end of the quarter, but distributed reasonably to prevent everyone from submitting all three refactors on the last day of class. You are free to submit a refactor early, but once a refactor deadline has passed, you will no longer be able to submit. Even though we do operate under quite a lenient late submission policy for assignments, refactor deadlines are final.

Completing all three refactors and receiving full credit on each will raise your grade one half letter. So if you have a B+, a perfect set of refactors will give you an A-. However, the maximum grade you can achieve through refactors is a 96% or A. Therefore, the only way to earn an A+ in this class is through high scores on original assignment submissions. Final refactor grades will be added to your grade after the quarter ends, but we will try to get your individual refactors graded within 1 week of your submission date.

How we will grade your submission

This assignment will be graded on a 2 point scale, with the 2 points being allocated completely to whether or not you submitted something that meets all of the above requirements. The following rubric will be used:

Documentation | 0.5 pts

Has the refactor plan been clearly articulated?

Are the changes clearly explained?

Implementation of Improvement | 0.5 pts

Has the refactor plan been fully executed?

Do the improvements meet the requirements for a refactor?

Function | 1.0 pts

Does the refactored program work?

Are there any bugs or errors?

Good luck. Try to have some fun with your refactors! This work should not be stressful. Remember, if you don’t want to complete a refactor you don’t have to.