Any code that is overly complex is a candidate for refactoring. Arithmetic statements should be as simple as possible so it's easy to understand their semantic intent. Learn how to use the Simplify Arithmetic refactoring to simplify overly complex arithmetic statements.
- [Instructor] I've gone ahead and extracted methods…to identify the other special items,…and I've included a copy of my code…so you can begin at the same point as me.…Here's another kind of expression that I'm seeing…repeated in this code.…At line 24, we see a line that says…item.quality equals item.quality minus one.…At line 29, item.quality equals item.quality plus one.…These sorts of expressions can be simplified.…We can simplify the arithmetic of these expressions…to decrement the value of a variable at by one.…
We could simplify this to be item.quality minus minus.…Having done that, let's rerun the tests…to make sure we didn't break anything.…Alright, so the pin down tests are continuing…to keep us safe.…Let's try the same thing at line 29, we'll change this from…item.quality equals item.quality plus one…to the simpler item.quality plus plus, and rerun the tests.…
We'll scroll down and continue making this kind of change.…So we've got another one at line 34.…Every time we do this, we'll rerun the tests…to make sure we didn't accidentally type minus minus…
Author
Released
2/1/2019- Defining refactoring
- Setting up a test-driven development environment
- Renaming variables
- Using the extract method
- Pinning down legacy code
- Testing code and branch coverage
- Refactoring legacy code
- Simplifying math and Booleans
- Adding new behaviors to refactored code
Skill Level Intermediate
Duration
Views
Related Courses
-
Agile Software Development
with Shashi Shekhar1h 53m Beginner -
Agile Software Development: Pair and Mob Programming
with Chiu-Ki Chan1h 36m Intermediate -
Agile Software Development: Scrum for Developers
with Shashi Shekhar2h 40m Intermediate
-
Introduction
-
1. Refactoring with New Code
-
Code kata1m 24s
-
Setting up the new code kata2m 30s
-
Refactoring: Rename Variable3m 47s
-
Micro-refactoring3m 47s
-
Refactoring: Inline Code4m 3s
-
Refactoring: Extract Method4m 38s
-
2. Stabilizing Legacy Code
-
Methodology2m 46s
-
Start writing pin-down tests3m 24s
-
Refactoring pin-down tests4m 40s
-
Code coverage4m 51s
-
Branch coverage4m 35s
-
3. Refactoring Legacy Code
-
Refactoring: Final steps3m 33s
-
Conclusion
-
Next steps47s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Refactoring: Simplify Arithmetic