Chapter 11Refactoring APIs
Modules and their functions are the building blocks of our software. APIs are the joints that we use to plug them together. Making these APIs easy to understand and use is important but also difficult: I need to refactor them as I learn how to improve them.
A good API clearly separates any functions that update data from those that only read data. If I see them combined, I use Separate Query from Modifier (306) to tease them apart. I can unify functions that only vary due to a value with Parameterize Function (310). Some parameters, however, are really just a signal of an entirely different behavior and are best excised with Remove Flag Argument (314).
Data structures are often unpacked unnecessarily when passed between ...
Get Refactoring: Improving the Design of Existing Code 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.