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 ...