From the course: Agile Software Development: Refactoring

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Refactoring: Simplify Booleans

Refactoring: Simplify Booleans

From the course: Agile Software Development: Refactoring

Start my 1-month free trial

Refactoring: Simplify Booleans

- [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…

Contents