Refactor to Break Up a Long Function
You may have already noticed a few things about the production code, which you’d like to clean up. But instead of making a lot of changes all at once, let’s apply the principles of refactoring. That’s why we have all these unit tests.
We could start anywhere, but for this worked example, let’s begin with a code smell. Martin Fowler describes what these are:
A code smell is a surface indication that usually corresponds to a deeper problem in the system.…A smell by definition is something that’s quick to spot.[37]
The changePassword method has the Long Function smell. As we noted earlier, this one method has 116 lines. This makes it more difficult to understand. There are three sections, each marked by ...
Get iOS Unit Testing by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.