September 2019
Beginner to intermediate
494 pages
13h
English
Inline variable refactoring is used to remove redundant usage of variables. Consider our current distance() method in the Point class:
def distance(self, p): diff = self - p distance = sqrt(diff.x**2 + diff.y**2) return distance
We can see that, after the distance variable is declared, it is immediately returned by the method. We would like to combine these two lines of code into one so that we can simply return the sqrt(diff.x**2 + diff.y**2) expression.
However, doing this, you might argue, can be seen as the opposite of how we defined the general purpose of refactoring; after all, by getting rid of a variable, we are potentially making our code less readable and extendable. The readability of our code will not be affected ...
Read now
Unlock full access