Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor main#update_quality #1

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft

Refactor main#update_quality #1

wants to merge 38 commits into from

Conversation

dkubb
Copy link
Owner

@dkubb dkubb commented Jun 5, 2020

No description provided.

dkubb added 30 commits June 5, 2020 08:36
* This will execute the tests for each commit.
* This allows the tests to "pass" as long as the tests marked
  as pending continue to fail. This will allow me to refactor the
  existing code to be simple enough that adding support for the
  conjured items will be easier. Once support is added these
  tests will begin to fail, and the tests will no longer be marked
  as pending.
* Use the Replace Method with Method Object refactoring:

    https://refactoring.guru/replace-method-with-method-object

* A temporary ItemUpdater#item alias method is added to allow the
  code to remain mostly unchanged from the original. A future
  commit will remove the alias and allow the code to delegate
  implicitly via self rather than item.
* This forces the code to use explicit self instead of the item alias
  to access the delegated object.
* Add ItemUpdater#quality= and use Comparable#clamp to limit the
  upper and lower bounds on the quality.
* Remove all refundant upper and lower bounds checks in
  ItemUpdater#call.
* It is difficult to reason about negated conditionals, so when
  there is an if/else branch with a negative conditional I flipped
  the branches around so that it is easier to read and understand.
* If an else contains another if/else branch, then it can be
  collapsed and moved up to the parent branch.
* A future refactoring will transform this into an if/else
  condition, but I wanted to minimize the diff so that it
  was easier to understand in a smaller change.
* The nested conditional is not necessary, and it is cleaner to
  move it up to the parent conditional. Note that this does cause
  some minor duplication where the quality is incremented in
  the aged brie and backspace pass branches.
* When the quality is being incremented twice in the block it is
  a little more difficult to understand than a simple if/else/else
  block where it is incremented *exactly* the correct number of times
  based on the sell_in value.
* The code duplicates the quality mutator call when the only
  detail that differs is how much the value should be incremented.
* The quality reset used a redundant expression that can just be
  simplified to 0.
* This groups the quality changing code closer together so that
  it will be more clear when they are collapsed into the same
  logic, in an upcoming commit.
* The use of -quality effectively resets the quality back to
  0 after expiry, since a backstage pass is worthless after the event
  has finished.
* It can be more difficult to follow logic when values are mutated
  more than once in a given expression.
* This changes the logic so that self.quality is always incremented
  with += so that the value amount can be extracted into a separate
  method in a future commit.
* Use the Extract Method refactoring:

    https://refactoring.guru/extract-method
* Change main#update_quality to match the updater by the item name
dkubb added 6 commits June 5, 2020 10:16
* This allows the removal of the conditional logic in
  ItemUpdater#call
* This simplifies ItemUpdater#change_quality
* Refactor ItemUpdater#value_change to be simpler
* This simplifies ItemUpdater#value_change
@dkubb dkubb self-assigned this Jun 5, 2020
@dkubb dkubb marked this pull request as draft June 5, 2020 17:52
@dkubb dkubb force-pushed the dkubb/solution1 branch 4 times, most recently from 46c5a4a to a12a9a4 Compare June 5, 2020 18:50
@dkubb dkubb force-pushed the dkubb/solution1 branch 9 times, most recently from b837a0e to 0926520 Compare June 8, 2020 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant