If statements can be difficult to read and understand. When you notice conditionals that begin with the not operator, you've probably identified a Boolean expression that you can simplify. Apply the Invert Boolean and Simplify Boolean Expression refactorings to make it easier to read and understand your conditional code.
- [Instructor] Now another opportunity for improving…this code is to simplify some of these logic expressions.…Like at line 52 or line 53 where it says…if not isAgedBrie or if not isBackstagePasses,…call these inverted logic or backward logic.…What we're trying to ask is…if this item isn't a BackstagePass then do this,…otherwise if it is a BackstagePass do that.…That's difficult to understand,…and we can simplify that by instead saying…if it is a BackstagePass do this, otherwise do that.…
So that's the refactoring we'll do here.…We'll do the refactoring to invert this logic,…to simplify this logic.…We'll do this one manually.…So at line 53 we'll delete that not symbol,…at the end of the line press enter,…and put a right squiggly brace, type else,…and put a left squiggly brace.…Okay, so we've recaptured what to do…if it's not a BackstagePass.…And now lets take line 61,…we'll cut it and paste it at 53 and a half.…
Clean up by deleting this dangling else.…Re-run the tests,…and determine whether we've kept…the external behavior of the code.…
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 Booleans